1

I'm trying to create a fillable PDF form with hyperref and I want there to be a long line instead of a box for a text field. At the moment I'm using the following code:

\documentclass{scrartcl}

\usepackage{hyperref}
\usepackage{amsmath}

\renewcommand\LayoutTextField[2]{%
    #2
}

\begin{document}
    \begin{Form}
        Name: \dotfill$\overset{\TextField[width=4cm,borderwidth=0pt]{\null}}{\rule{4cm}{.4pt}}$
    \end{Form}
\end{document}

This works and achieves what I want but I was just wondering if there was a better way to do it? For some reason this solution seems inelegant to me.

5

You can set the borderstyle to underline. Or add some tikz and other code to the layout. In the second case set the colors to transparent. It is also often quite useful to move the field a bit down to get a better alignment with the label:

\documentclass[parskip=full-]{scrartcl}

\usepackage{hyperref}
\usepackage{tikz}
\usepackage{amsmath}


\begin{document}
\begin{Form}
\renewcommand\LayoutTextField[2]{%
 #2}

Name: \TextField[width=4cm,borderstyle=U]{nameA}{\rule{4cm}{.4pt}}

 \renewcommand\LayoutTextField[2]{%
   \raisebox{-3.2pt}{\tikz[overlay]\draw[dashed](0,-0.2\dp\strutbox)--++(\csname Fld@width\endcsname,0pt);#2}}

 Name: \TextField[width=4cm,bordercolor={},backgroundcolor={}]{nameB}{\rule{4cm}{.4pt}}


 \renewcommand\LayoutTextField[2]{%
  \raisebox{-\dp\strutbox}{\makebox[0pt][l]{\cleaders \hbox to .44em{\hss.\hss}\hskip\csname Fld@width\endcsname}}#2}

 Name: \TextField[width=4cm,bordercolor={},backgroundcolor={}]{nameC}{\rule{4cm}{.4pt}}
\end{Form}
\end{document}

enter image description here

  • 1
    Great! Thanks. I tried looking for a borderstyle option in the hyperref manual but couldn't find any. I love the simplicity of that solution. Also, I'm doing it the other way round from what you suggested. I added a raisebox to the label to align it with the text field better. – K G Oct 31 '17 at 14:37
  • Ok borderstyle=U doesn't work. – K G Oct 31 '17 at 14:44
  • Works for me as you can see in the screenshot, but it can depend on the pdf viewer. – Ulrike Fischer Oct 31 '17 at 14:45
  • Indeed you are correct. It works in Acrobat. That's strange. I guess the TikZ solution is the only feasible one then. – K G Oct 31 '17 at 14:47
  • I'm also wondering where the syntax for borderstyle=U is documented. I couldn't find anything in ctan.mirror.colo-serv.net/macros/latex/contrib/hyperref/doc/… – Fuhrmanator Aug 15 '18 at 16:45

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.