2

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}
  • 1
    Hove you tried overlapping them, using \rlap and possibly \raisebox? – John Kormylo Feb 2 '16 at 4:16
  • The [0ex] in your command is telling TeX you want the rule raised by 0ex. Perhaps something like [2ex] would suit you better. – jon Feb 2 '16 at 4:32
  • Hell World, or Hello World? :-) – Mico Feb 2 '16 at 7:29
3

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

  • 1
    Or: John Smith\par \rule[2ex]{\linewidth}{0.5pt} (with \noindents as appropriate -- hard to say in OP's question how \parindent is working). --- Love the "Hell world" though: how all cover letters should start! – jon Feb 2 '16 at 5:19
  • @jon regarding "Hell world", just following the OP's lead, but really I couldn't resist. – A.Ellett Feb 2 '16 at 5:21
  • .... Ha, indeed! – jon Feb 2 '16 at 5:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.