Text Formatting ⇒ hrule on same line as text
hrule on same line as text
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 -------------------
Section 4.3 -------------------
Last edited by jaybz on Mon Dec 13, 2010 9:55 pm, edited 1 time in total.
NEW: TikZ book now 40% off at Amazon.com for a short time.

hrule on same line as text
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}
Re: hrule on same line as text
Is there a way to still control the line thickness with strike out ?
hrule on same line as text
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}
hrule on same line as text
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.


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}
hrule on same line as text
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}
hrule on same line as text
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!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,
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}
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}
Re: hrule on same line as text
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.