134

In LaTeX, how would I make a long underscore?

For example,

Name _______  Signature _______
lockstep
  • 250,273
Neil G
  • 17,947
  • 7
    Those should be lines (rules) and not underscores. – Caramdir Aug 03 '11 at 04:22
  • 2
  • 3
    @Caramdir Oddly though, the simple solutions like mine and Jake's don't appear there. – Alan Munn Aug 03 '11 at 04:34
  • @Alan: Yes, I noticed that. – Neil G Aug 03 '11 at 04:35
  • Perhaps the best thing to do is to close this question and add the simple solutions to the other question? I'll upvote them. – Neil G Aug 03 '11 at 04:36
  • 6
    @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 03 '11 at 04:39
  • Might I ask what possessed you to come back and unaccept my answer in favor of one that had been around long before I made mine? It feels discourteous. – Ryan Reich Jun 12 '13 at 22:09
  • 2
    @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
  • No it's not the reputation (as you say). I'm just taken aback since its been so long. – Ryan Reich Jun 13 '13 at 09:10
  • @RyanReich: Ok, sorry again. – Neil G Jun 15 '13 at 00:05

7 Answers7

156

You can just \underline a \hspace:

\documentclass{article}

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

\end{document}

underlined spaces

Jake
  • 232,450
  • 5
    Is this better than just using a rule? If so, how? – Seamus Aug 03 '11 at 10:39
  • 4
    @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 03 '11 at 12:54
  • 2
    @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 03 '11 at 23:13
  • 4
    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
46

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.

Alan Munn
  • 218,180
27

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.

Ryan Reich
  • 37,958
16

A code such as

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

in your preamble allows you to say

\blank{2cm}

instead of your complicated construction.

egreg
  • 1,121,712
14

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:

enter image description here

\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.

Werner
  • 603,163
10

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:

result

Marco
  • 26,055
3

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}
Peter Grill
  • 223,288
  • 3
    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 03 '11 at 05: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 03 '11 at 05:35