I'm trying to create a underlined heading like this, without space between John Smith and the underline
I tried this command, but it adds a vertical gap between the name and the underline
\noindent\rule[0ex]{\linewidth}{0.5pt}
Best Answer
Try this
\documentclass{article}
\begin{document}
\noindent
\makebox[0pt][l]{\Large\bfseries John Smith}%%
\rule[-0.5ex]{\columnwidth}{0.4pt}
Hell world, this is my cover letter.
\end{document}
There are commands like \rlap and \\lap. But, I think \makebox is kind of fun. You can set the width of the box and the alignment to be left, right, or center.
\documentclass{article}
\begin{document}
\noindent
\rule[-0.5ex]{\columnwidth}{0.4pt}%%
\hspace*{-\dimexpr\columnwidth/2}%%
\makebox[0pt]{\Large\bfseries John Smith}%%
\hspace*{\dimexpr\columnwidth/2}%%
Hell world, this is my cover letter.
\end{document}
Following this general idea, you can create nice commands like the following
\documentclass{article}
\newif\ifaeShowAnswers
\newcommand\aeShowAnswer[2]{%%
\rule[-0.5ex]{#1}{0.4pt}%%
\hspace*{-\dimexpr#1/2}%%
\makebox[0pt]{\ifaeShowAnswers#2\fi}%%
\hspace*{\dimexpr#1/2}}
%%\aeShowAnswerstrue
\begin{document}
Lord \aeShowAnswer{1.25in}{Voldemort} is the \aeShowAnswer{1.25in}{Harry Potter}'s archnemesis.
\end{document}
results in
By uncommending the line with \aeShowAnswerstrue results in
\vspace doesn't take effect until you are in vertical mode. \blindtext probably doesn't end with \par or a blank line, so it's still in horizontal mode when the environment ends. put \par at the beginning of the end code for the environment to force the vertical space above the rule:
{\par\nobreak\vspace{5\bigskipamount}\HorzLine}
EDIT: added \nobreak to prevent a page break just before the \HorzLine.
Best Answer
Try this
There are commands like
\rlap
and\\lap
. But, I think\makebox
is kind of fun. You can set the width of the box and the alignment to be left, right, or center.Following this general idea, you can create nice commands like the following
results in
By uncommending the line with
\aeShowAnswerstrue
results in