19

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?

Nik
  • 601
  • 3
  • 6
  • 15
  • Solution which Martin posted here is not present in question you provided – Nik 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. – Nik 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
  • Thanks, but I want to know if its possible to say like width: 100% in html. I mean, how can I tell latex to stretch line from its origin point to document's right margin? Because I don't know how long it should be in cm (I have several fields one by one and they all starts with phrase of different length, like 'name' or 'phone number' and so on). – Nik May 13 '12 at 20:50
  • 1
    @dig, look at my updated answer. – JohnReed May 13 '12 at 20:57

6 Answers6

15

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}
Jake
  • 232,450
14

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.

JohnReed
  • 2,627
  • 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? – Nik May 13 '12 at 20:26
  • 1
    @dig See my modified answer. – JohnReed May 13 '12 at 20:50
8

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

Martin
  • 2,628
6

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}
David Carlisle
  • 757,742
Alan Munn
  • 218,180
6

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}
Marco Daniel
  • 95,681
5

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}​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​
Peter Grill
  • 223,288