# How to continue thick underline beyond text?

Here's my code:

\documentclass[12pt]{article}
\usepackage{soul}
\begin{document}
\setul{}{2pt}
\ul{\Huge\textbf{Some text}}
\underline{\Huge\textbf{Some text \hspace{1in}}}
\ul{\Huge\textbf{Some text \hspace{1in}}} % This line causes error
\end{document}


The command \underline{\Huge\textbf{Some text \hspace{1in}}} produces the result

I want the underline to be thicker though, so I tried using the soul package, setting the thickness, and then \ul{Some text}

This gives me the desired underline thickness

The problem occurs when I try to combine the two to get a thick line extending beyond the text. The command \ul{\Huge\textbf{Some text \hspace{1in}}} produces an error, "Missing number, treated as zero."

Any ideas why or how to fix it? Or better ways of underlining text with a bold line that extends an arbitrary distance beyond the text?

• Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Apr 12 '15 at 0:03
• Try \protect\hspace*{1in} – user31729 Apr 12 '15 at 0:08
• Doing \ul{\Huge\textbf{Some text \protect\hspace{1in}}} fixes the error but cuts the underline off at the end of the text... produces same result as second image above – Philip Apr 12 '15 at 0:14
• \ul{\Huge\textbf{\mbox{Some text \hspace{1in}}}} – user31729 Apr 12 '15 at 0:18
• @ChristianHupfer I'm jealous. You knew the answer, I had to look it up in the package manual. :( – R. Schumacher Apr 12 '15 at 0:20

You have to read the fine print in the soul manual http://texdoc.net/texmf-dist/doc/latex/soul/soul.pdf You have to protect with \mbox{}.

\documentclass[10pt,letterpaper]{article}
\usepackage{soul}
\begin{document}
\ul{\Huge\textbf{Some text\mbox{\hspace{1in}}}}
\end{document}

• Great, that worked for me, thanks. I read that doc but didn't realize that line of the table applied. – Philip Apr 12 '15 at 0:22

Without loading any other packages, here's a command that will accomplish this using a rule.

\documentclass{article}
\makeatletter
\newlength\ae@tmp@length
\newcommand\aeunderline[2][]{%%
\settowidth\ae@tmp@length{#2}%%
\makebox[0pt][r]{#2}%%
\hspace{-\ae@tmp@length}%%
\rule[\dimexpr-0.25ex-4pt]{\dimexpr\ae@tmp@length+#1+0pt\relax}{4pt}}

\makeatother

\pagestyle{empty}
\begin{document}

\aeunderline[2in]{Hello World} and this is what follows.

\end{document}


## plain TeX based

A solution with underline based on plain TeX means only:

\documentclass{article}
\begin{document}
\leavevmode
\vtop{
\Huge
\hbox{\textbf{Some text \hspace{1in}}}
\kern.5ex % space between text and line
\hrule height 2.5pt % rule thickness
}
\end{document}


## TikZ based

The following example uses TikZ, which offers more options regarding the line style. For example, this version shows round line caps:

\documentclass{article}
\usepackage{tikz}
\begin{document}
{\Huge
\tikz[
baseline=(text.base),
node font=\bfseries,
inner sep=0pt,
line width=2.5pt,
line cap=round, % also decorations, ...
]
\draw
node (text) {Some text}
(text.south east) ++(1in, -.5ex) coordinate (tmp)
-- (text.south west |- tmp)
;}
\end{document}


Just for completeness of the answers to this question, if you are using luatex, there is an unfinished package that underlines: luauline. (It is usable, it just isn't ready enough for CTAN since it has no documentation and needs a few performance improvements.)

If you download this package and place it in your local TeX tree, you can load it and produce the desired result with the following:

\documentclass[12pt]{article}
\usepackage{luauline}
\setluaunderlineheight{2pt}  % set thickness of the underline
\begin{document}
\uline{\Huge\textbf{Some text\hspace*{1in}}}
\end{document}