Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
dynamic signature/date line

How can I make text under line in a form like this:

____________________
    name, phone

Or

Name:____________________
         (full name)

Thanks!

update:

Solution that two users provided works well for fixed-size hspace. It is also easy to make a function from it.

Name: $\underset{\text{(full name)}}{\underline{\hspace{5cm}}}$

However I am wondering if it is possible to use kind of dynamic hspace? Or it is completely different issue?

share|improve this question
    
Solution which Martin posted here is not present in question you provided –  dig May 13 '12 at 20:15
    
True, it is not exactly the same (minor formatting and alignment), but it is similar in nature, hence the suggestive duplicate. It might be different if you had referenced that (or a similar question) with a specific difference to it saying why the solutions proposed is insufficient, or where you got stuck with reformatting it suit your needs. –  Werner May 13 '12 at 20:27
    
Actually I still have troubles, trying to figure out in comments. Will update my question. –  dig May 13 '12 at 20:31
1  
You can create a function of this: \newcommand*{\fullname}[1][5cm]{$\underset{\text{(full name)}}{\underline{\hspace*{\dimexpr#1}}}$} and then use \fullname, or \fullname[7cm] or \fullname[2in], or \fullname[1cm+3in]. Note the optional/square brackets. Default, without brackets, is 5cm. –  Werner May 13 '12 at 20:35
1  
@dig, look at my updated answer. –  JohnReed May 13 '12 at 20:57
show 1 more comment

marked as duplicate by Werner, lockstep, Alan Munn, percusse, Marco Daniel May 17 '12 at 8:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

6 Answers

up vote 8 down vote accepted

Here is a solution based on (a probably abused) math mode. I defined a new command called \tline to make it more straightforward. The first argument is the text that you want underneath the line and the second argument is the length of the line that you want.

Code/Example:

\documentclass[]{article}

\usepackage[]{amsmath}

% THIS IS MY NEWLY DEFINED COMMAND
\newcommand\tline[2]{$\underset{\text{#1}}{\text{\underline{\hspace{#2}}}}$}

\begin{document}

Name: \tline{(full name)}{1in}

\end{document}

Output: sample output

Edit: I modified the code so that the underline will fill the rest of the line. The technique was based off of this answer to another question.

Additional Preamble Code:

% Code based on http://www.latex-community.org/forum/viewtopic.php?f=44&t=10246
\newsavebox\mybox
\newlength\mylen
\newlength\fieldlen
\newcommand\tlinefill[2]{\noindent #1\sbox\mybox{#1}%
\settowidth\mylen{\usebox\mybox}%
\setlength\fieldlen{\linewidth}%
\addtolength\fieldlen{-\mylen}%
$\underset{\text{#2}}{\text{\underline{\hspace{\fieldlen}}}}$}

Using the new command \tlinefill, the line can fill the rest of the line. The first argument is the text that you want in front of the line and the second argument is the text that you want underneath the line. So, \tlinefill{Name: }{(full name)} will produce:

more output

Note that the lipsum text is there just to show the line width.

share|improve this answer
1  
I just realized that Martin reached pretty much exactly the same solution that I did. The only difference is the definition of a command to make it easily reusable. –  JohnReed May 13 '12 at 20:16
    
Yep actually looks similar. Is it possible to use kind of dynamic hspace so that it will grow to the right border of page? –  dig May 13 '12 at 20:26
1  
@dig See my modified answer. –  JohnReed May 13 '12 at 20:50
    
Thank you very much! –  dig May 13 '12 at 20:58
add comment

Or a \shortstack that's lowered by -\baselineskip using \raisebox:

\documentclass{article}

\begin{document}
How now \raisebox{-\baselineskip}{\shortstack{\underline{\hspace{3cm}}\\(brown cow)}}?
\end{document}
share|improve this answer
    
+1 for the laugh. –  JohnReed May 14 '12 at 3:13
add comment

Another possibility is to use \underset command from the amsmath package, e.g.

\documentclass{article}
\usepackage{amsmath}
\pagestyle{empty}
\begin{document}
$\underset{\text{name, phone}}{\underline{\hspace{5cm}}}$
\vspace*{2cm}

Name: $\underset{\text{(full name)}}{\underline{\hspace{5cm}}}$
\end{document}

enter image description here

share|improve this answer
    
Is it possible to make \hspace fill all available space from left to right? –  dig May 13 '12 at 19:59
    
For me this is the best solution because it doesn't break lines height like others. –  dig May 13 '12 at 19:59
add comment

There are probably many ways to do this. One would be to use a tabular environment:

\begin{tabular}{lc}
Name: & \underline{\hspace{2in}}\\
& \textsf{(full name)}
\end{tabular}
share|improve this answer
add comment

You can use a tabular environment

\documentclass[]{article}
\usepackage{array}
\begin{document}
Name \begin{tabular}[t]{c}\hline \makebox[4cm][c]{(full name)} \\\end{tabular}

\end{document}
share|improve this answer
add comment

You could also use a minipage:

enter image description here

\documentclass{article}
\newcommand{\TextLine}[2][5cm]{%
\begin{minipage}{#1}
    \par\noindent\hrule\smallskip
    \small \makebox[#1]{\textbf{#2}}
\end{minipage}
}
\begin{document}
    \TextLine{name, phone} 
​\end{document}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
share|improve this answer
add comment

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