latex hyperref choicemenu box is wider than specified for long text

Viewed 254

I'm trying to prepare a fillable pdf-form using MikTeX\LaTeX. I use the ChoiceMenu from the hyperref package to provide a list to choose from. The problem is that I want the field to have a width of 2 cm. I have specified the required width in the parameter of the ChoiceMenu. So far, no problem. But when I include a choice option longer than 2 cm in the list, the ChoiceMenu field gets wider than 2 cm. Is there a way to force the program to keep the specified width of 2 cm, even though the text is not completely readable in the field after choosing?

Here is a minimal working example:

\documentclass[landscape]{scrartcl}
\usepackage[top=2cm, bottom=3cm, left=2cm, right=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

% begin document
\begin{document}
\begin{Form}
      \begin{tabular}{l}
            \mbox{\ChoiceMenu[combo, name=test_choice, width=2cm]{Working choice field (2 cm width):}{short 1, short 2}} \\\\
      \mbox{\ChoiceMenu[combo, name=test_choice, width=2cm]{Non-working choice field (2 cm width):}{short 1, this is a very long sentence leading to a much greater field width than specified}}
      \end{tabular}
\end{Form}
\end{document} 
1 Answers

You can hide the width of your text like this:

\documentclass[landscape]{scrartcl}
\usepackage[top=2cm, bottom=3cm, left=2cm, right=2cm]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage[T1]{fontenc}
\usepackage{hyperref}

\newcommand{\hide}[1]{\texorpdfstring{\makebox[0pt]{#1}}{#1}}

% begin document
\begin{document}
\begin{Form}
      \begin{tabular}{l}
            \mbox{\ChoiceMenu[combo, name=testchoice, width=2cm]{Working choice field (2 cm width):}{short 1, short 2}} \\\\
      \mbox{\ChoiceMenu[combo, name=testchoice, width=2cm]{Non-working choice field (2 cm width):}{short 1, \hide{this is a very long sentence leading to a much greater field width than specified}}}
      \end{tabular}
\end{Form}
\end{document} 

enter image description here

Related