# Long underscore in LaTeX

In LaTeX, how would I make a long underscore?

For example,

Name _______  Signature _______
-
Those should be lines (rules) and not underscores. –  Caramdir Aug 3 '11 at 4:22
possible duplicate of How can i add a "field" for handwritten text? –  Caramdir Aug 3 '11 at 4:22
@Caramdir Oddly though, the simple solutions like mine and Jake's don't appear there. –  Alan Munn Aug 3 '11 at 4:34
@Neil I think the way you've posed the question is nice and simple and captures what many people have a need for; the other question is really quite a bit more complicated, so I think we shouldn't close this one. (I'd also wait a bit before accepting either answer.) –  Alan Munn Aug 3 '11 at 4:39
@RyanReich: Oh geez :( I really didn't mean to be discourteous. To be fair, I had already upvoted your answer and the other one, but looking back, I thought the underline solution produced a rule that was below the text and that seems better to me now. I thought since all three top answers had 10k+ rep, you wouldn't even notice! If you think reaccepting yours is more courteous, I'd be happy to. –  Neil G Jun 12 '13 at 22:49

You can just \underline a \hspace:

\documentclass{article}

\begin{document}
Name \underline{\hspace{3cm}}
Signature \underline{\hspace{3cm}}

\end{document}

-
Is this better than just using a rule? If so, how? –  Seamus Aug 3 '11 at 10:39
@Seamus -- using \hspace isn't necessarily "better" than just using a rule, but if you are placing the rule after a word, the \underline will place it lower than the baseline, which looks better in most cases. so it saves a bit of decision making. –  barbara beeton Aug 3 '11 at 12:54
This is the easiest solution –  Neil G Aug 3 '11 at 22:46
@Seamus: It also uses the standard line thickness, so you don't run the risk of making the line slightly too thick or thin. –  Jake Aug 3 '11 at 23:13
Use #em instead of #cm in order to make the length of the underscore depend on the font’s width. –  Júda Ronén Dec 30 '14 at 17:38

You can use \rule:

\rule[<raise height>]{<width>}{<height>}

For example \rule{2in}{.5pt} will give you the sort of thing you want.

The optional argument can be used to raise (positive value) or lower (negative value) the rule. Sometimes lowering it slightly looks better.

-
This is a good solution if you want fine control over the dimensions. –  Neil G Aug 3 '11 at 18:54

If you want a line (or rule) at the baseline of a specific length (and width), you can just use \rule{<len>}{<width>}. You can also adjust the vertical displacement (or depth) by adding an optional argument: \rule[<depth>]{<len>}{<width>}.

Here's a mock-up using an example:

\documentclass{article}
\newcommand{\uline}[1]{\rule[0pt]{#1}{0.4pt}}% Fill this blank
\begin{document}
Assume $A \subset B$.
We want to show $A \subset (A \cap B)$ and \uline{2cm}.
The first fact is true since: $A \subset B \Rightarrow$
if $x \in A$ then \uline{2cm} $\Rightarrow$
if $x \in A$ then $x \in A and B$.
The second fact is true by \uline{2cm}.

Conversly, assume \uline{2cm}.
By the first property again, $B \supset$ \uline{2cm},
so we have \uline{4cm}.
\end{document}​​​​​​​​​​​

I've defined \uline to take a single argument, fixing the others passed to \rule (width is 0.4pt and depth is 0pt). You can modify this as required, depending on the preference.

-
I'm confused - the answer does not modify \rule anymore, but it still seems like it did. Could somebody mark the update? –  Blaisorblade Mar 26 '13 at 12:11
@Blaisorblade: Yes, I'll flag the comments as obsolete and request a moderator to remove them. You can see the original entries as part of the post history/revisions. –  Werner Mar 26 '13 at 14:21

As I learned from the exam class's documentation, you can do this:

\makebox[0.5\textwidth]{Name:\enspace\hrulefill}

which allows you to control how much space the entire construction takes up, rather than just the underlined part.

-

In ConTeXt you can use the command \thinrules. The optional parameter n outputs a particular amount of lines. Example:

\starttext

Some text \thinrules[n=1]
\blank
Some text \thinrules[n=2]

\stoptext

The result:

-

A code such as

\newcommand\blank[1]{\rule[-.2ex]{#1}{.4pt}}

in your preamble allows you to say

\blank{2cm}

-

You can also use the soul package. This has the added benefit that the underline can be of a different color, and also should be able to work across paragraph boundaries (except that there appears to be a bug, so had to add the \mbox below for now.

\documentclass{article}
\usepackage{xcolor}%
\usepackage{soul}%

\newcommand{\UnderlineText}[2][red]{\setulcolor{#1}\ul{#2}}%

\begin{document}
Signature \UnderlineText[blue]{\mbox{\hspace{5cm}}}
\end{document}
-
If all you want is a coloured line, you don't need the soul package. Instead, you can just use the \color command from the xcolor package: \color{red}{\underline{\hspace{3cm}}} –  Jake Aug 3 '11 at 5:31
@Jake: Good point. I have been using the \UnderlineText to obtain an underline of a different coloring than the text, but since in this case there is no text that is not really an issue. Hopefully, once the related problem is solved, this solution will be of some use as the \ul will handle line boundaries. –  Peter Grill Aug 3 '11 at 5:35