Text Formattinghrule on same line as text

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

hrule on same line as text

Post by jaybz »

How can I make a horizontal line that is on the same line as some text and be aligned to the middle of the text?

Section 4.3 -------------------
Last edited by jaybz on Mon Dec 13, 2010 9:55 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

hrule on same line as text

Post by frabjous »

You might consider using the \sout (strike out) command from the ulem package along with some spacing command, e.g.:

Code: Select all

\documentclass{article}
\usepackage[normalem]{ulem}
\begin{document}

Some text \sout{\hfill} 

\end{document}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: hrule on same line as text

Post by jaybz »

Is there a way to still control the line thickness with strike out ?
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

hrule on same line as text

Post by frabjous »

It seems to use the value of \ULthickness for the thickness, which you can change using \renewcommand.

Code: Select all

\documentclass{article}
\usepackage[normalem]{ulem}
\renewcommand{\ULthickness}{2pt}

\begin{document}

Some text \sout{\hfill} 

\end{document}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

hrule on same line as text

Post by jaybz »

Sorry to reopen here but I have another problem. Using your method I get quite a bit of space between the text and the line, as in "Section 1" If I use another method "Section 2" I can control the space but the line isn't in the right place. Also I have to use a bunch of "newline's" because "vspace" won't work.
Image

Code: Select all

\documentclass[12pt]{article}
\usepackage[top=23mm, bottom=20mm, left=25mm, right=25mm]{geometry}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{helvet}
\usepackage{setspace}
\usepackage{pbox}
\usepackage[normalem]{ulem}
\renewcommand{\ULthickness}{2pt}
\pdfpagewidth 215mm
\pdfpageheight 266mm
%--------------------------------------------------------------------
\begin{document}

\textbf{Section 1}\newline
\vspace{-2mm}
\hspace{15pt}\sout{\hfill} 
\newline
\newline
\newline
\hspace*{6mm}Some text \ldots
\newline
\newline

\textbf{Section 2}
\vspace{2mm}
\hspace*{15mm}\hrule width 160mm height 2pt
\end{document}
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

hrule on same line as text

Post by shadgrind »

Don't know if this is what you're looking for, but this is how I usually do it:

Code: Select all

\documentclass{article}
\begin{document}
Some text \rule[2pt]{1in}{2pt}\vspace{3mm}

Some more text
\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

hrule on same line as text

Post by frabjous »

jaybz wrote:Sorry to reopen here but I have another problem. Using your method I get quite a bit of space between the text and the line,
Not to be rude, but nothing there counts as "my method". This thread was originally about placing the horizontal rule on the same line, centered, as the text. You are now trying to do something completely different, and I would suggest completely different methods!

For greater control over spacing, I recommend putting the text and the line in separate paragraphs rather than using \newline. The "wrong position" problem comes from not taking into account that the first line of a paragraph is indented. You can suppress this behavior using \noindent. Probably you want to do this with both the text, and the rule, or with neither. Compare, e.g., Section 1 and Section 2 in this example.

Rather than using \vspace commands, I'd just use the \rule command, and use its first optional argument which controls the vertical position of the bar. The syntax is \rule[vertical position]{width}{thickness}. I in Section 3 to show that vspace does the same thing (and works with paragraph breaks).

Code: Select all

\documentclass[12pt]{article}
\usepackage[top=23mm, bottom=20mm, left=25mm, right=25mm,papersize={215mm,266mm}]{geometry}
%--------------------------------------------------------------------
\begin{document}

\noindent\textbf{Section 1}

\noindent\rule[1ex]{\textwidth}{2pt}

\bigskip

Some text

\bigskip

\textbf{Section 2}

\rule[1ex]{\textwidth}{2pt}

\bigskip

Some more text

\bigskip

\textbf{Section 3}

\vspace*{-15ex}\rule{\textwidth}{2pt}

\end{document}
But really, you ought to be using sectioning commands rather than putting in the words "section X" in bold in normal paragraphs. The titlesec package has some commands for adding rules above and below sectioning commands. Let's see if I can work up an example...

Something like this?

Code: Select all

\documentclass[12pt]{article}
\usepackage[top=23mm, bottom=20mm, left=25mm, right=25mm,papersize={215mm,266mm}]{geometry}
%--------------------------------------------------------------------
\usepackage[calcwidth]{titlesec}
\titleformat{\section}% sectioning command formatted
            {\bfseries}% font commands applied to whole
            {Section~\thesection.}% label
            {0.5em}% separation between label and title
            {}% commands before section title
            [{\titlerule[2pt]}]% commands after
\begin{document}

\section{A section}

Some text

\section{}

Some more

\end{document}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: hrule on same line as text

Post by jaybz »

Thanks shadgrind, I just found documentation on "rule" that's what I went with. Thanks for your reply as well frabjous. I think I was getting my posts mixed up. I also just discovered the \noindent, good suggestion.
Post Reply