[Tex/LaTex] Underlined text field in a fillable form

formstext-decorations

Is there a way to make an underlined text field in a fillable form?

I am using the hyperref package to make a fillable form but I would also like to give the option of printing out the form and filling it by hand. For the later, a line is helpful to serve as guide for the pen.

This

\TextField[name=firstname,width=5cm,charsize=11pt]{First Name}

gives an empty box and I cannot find an easy way to underline this box.

Best Answer

The printing of the field is controlled by \MakeTextField whose default definition is equivalent to

\newcommand{MakeTextField}[2]{\vbox to #2{\hbox to #1{\hfill}\vfill}}

Replacing the inside \hfill with an \hrulefill produces a horizontal line, but because of the placing of the \vfill these will be at the top of the box. Moving the placement of \vfill gives a line at the bottom via

\renewcommand{\MakeTextField}[2]{{\vbox to #2{\vfill\hbox to #1{\hrulefill}}}}

You will probably want to adjust the colour to black (rather than the gray I get as default):

Sample output

\documentclass{article}

\usepackage{hyperref,xcolor}

\renewcommand{\MakeTextField}[2]{{\vbox to #2{\vfill\hbox to #1{\hrulefill}}}}

\begin{document}
\begin{Form}
  \TextField[name=firstname,width=5cm,charsize=11pt,color=black]{First Name}
\end{Form}
\end{document}