9

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.

8

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}
  • Strangely, this doesn't seem to do anything in pdflatex, though it does give lines in xelatex. You wouldn't know why that is, would you? – leftaroundabout Apr 1 '15 at 13:43
  • The above sample is pdflatex, so I guess it is an April fool. – Andrew Swann Apr 8 '15 at 12:23
  • This also does not work for me on a recent version of pdflatex (but works fine with xelatex). It results in an overfull vbox as well. – Sam Whited Apr 27 at 16:12
  • @SamWhited Still working fine for me (pdflatex an a mac, texlive 2018). Perhaps you should make a new post with your set-up details. – Andrew Swann Apr 28 at 16:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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