[Tex/LaTex] Horizontal line without vertical gap

rulesspacing

I'm trying to create a underlined heading like this, without space between John Smith and the underline

enter image description here

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}

enter image description here

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}

enter image description here

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

enter image description here

By uncommending the line with \aeShowAnswerstrue results in

enter image description here