3

I am writing this question after seeing this one as I had no idea that you could make forms like that in TeX.

Playing a bit with the code in that example I came across two issues I could not find how to change with the \TextField[parameters]{label}environment.

How to set the number of lines in a multiline environment and how to move the label at the top rather than the bottom of the multiline box.

According to the manual the option for the multiline environment is just a boolean parameter

multiline boolean false whether text box is multiline

and the label appears at the bottom rather than the top.

3
  1. To specify the height of a multiline text fielf, use the optional argument height, such as

    \TextField[multiline=true,height=6\baselineskip,...]{Comments}\
    
  2. For vertical alignment, you could use \height which gives he height of a box, together with \raisebox, such as

    \renewcommand*{\LayoutTextField}[2]{\makebox[6em][l]{#1: }%
      \raisebox{\baselineskip}{\raisebox{-\height}{#2}}}
    
  3. You could even adjust the default height of a multiline text field, like

    \renewcommand*{\DefaultHeightofTextMultiline}{6\baselineskip} 
    

Here's a complete example for this, re-using the code of the linked question:

\documentclass{article}
\usepackage{hyperref}
\renewcommand*{\DefaultHeightofTextMultiline}{6\baselineskip} 
\renewcommand*{\LayoutTextField}[2]{\makebox[6em][l]{#1: }%
  \raisebox{\baselineskip}{\raisebox{-\height}{#2}}}
%\renewcommand*{\LayoutTextField}[2]{% or this or similar ...
  %\raisebox{-\height}{\makebox[6em][l]{#1: }}\raisebox{-\height}{#2}}
\def\LayoutChoiceField#1#2{\makebox[6em][l]{#1: }#2}
\newdimen\longline
\longline=\textwidth\advance\longline-6em
\begin{document}
\begin{Form}
\TextField[name=Name,width=\longline,borderwidth=0,bordersep=4pt,
  backgroundcolor={.85 .85 .85}]{Name}\vskip1ex

\TextField[name=Affiliation,width=\longline,borderwidth=0,
  backgroundcolor={.85 .85 .85},]{Affiliation}\vskip1ex

\ChoiceMenu[borderwidth=0,radio=true,
  backgroundcolor={.85 .85 .85}]{Are you a}{Student, Academic}\\

\TextField[name=Comment,multiline=true,height=6\baselineskip,
  width=\longline,borderwidth=0,backgroundcolor={.85 .85 .85}]{Comments}\\
\end{Form}
\end{document}

enter image description here

  • Is there a particular reason that the same code does not provide the same results with XeLatex? Everything appears to be misaligned again. I am using Xelatex for the fontspec package as I am trying to use a system font not available to pdftex – o4tlulz Jun 16 '12 at 10:05
  • @o4tlulz Interesting! I noticed that too. However, it works fine with LuaLaTeX. Could you use that? – Stefan Kottwitz Jun 16 '12 at 17:51
  • I have a question, when I use backgroundcolor, it changes the background color when I click on the field, but as soon I filled the field and press enter, the default background color comes back. Any idea why ? – joseldsm Oct 30 '18 at 10:38
  • it works perfectly for me until a few \textfield. After i do like 4 they start to group together in pairs so it just messes with the spacing between the text fields – Jettie Baker Aug 28 '19 at 15:56

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.