2

I have to recreate an old form using latex. It includes a table where multiple questions are associated to some radio buttons.

I managed to create most of the form and table using hyperref and array, but now have a problem in the horizontal alignment of the radio buttons. As you can see in the screenshot the radio buttons are not center-aligned, but somewhat shifted to the right.

How to center-align the radio buttons in the 3 right columns?

enter image description here

\documentclass{report}

\usepackage{hyperref}
\usepackage{array}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}
\begin{Form}

\noindent\begin{table}[!h]
  \begin{tabular} {|m{8cm}|C{0.75cm}|C{0.75cm}|C{1.5cm}|}
    \cline{2-4}
    \multicolumn{1}{c|}{} &
    Yes & No & Maybe \\
    \hline
    Some question? &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=yes} &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=no} &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=maybe} \\
    \hline
    Some other question? &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=yes} &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=no} &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=maybe} \\
    \hline
  \end{tabular}
\end{table}

\end{Form}
\end{document}
4
  • with your code i can't reproduce your image. the radio buttons are not visible. it seems that something is missing in code.
    – Zarko
    Apr 30 '19 at 8:55
  • @Zarko strange - I just literally copied over the above to code to a new project and recompiled it. Still the radio buttons show up (Foxit reader). I'm using Miktex on Windows here.
    – Sirko
    Apr 30 '19 at 9:43
  • i use MikTeX too, but for viewer Sumatra. i didn't check other pdf viewers.
    – Zarko
    Apr 30 '19 at 9:52
  • 1
    I get nothing visible when viewing with mupdf, red squares when viewing using evince, grey squares with a red circle only in the chosen option in opera browser (linux), so I guess it's a viewer issue. Apr 30 '19 at 10:30
2

The macro \LayoutChoiceField{<label>}{<field>} controls how your radiobuttons are printed and is predefined to the effect of

\newcommand*\LayoutChoiceField[2]{#1 #2}

Note the space between label and field. This space shifts the field to the right in your table. Just redefine

\renewcommand*\LayoutChoiceField[2]{#1#2}

to get rid of it. (You could even leave out #1 if you never ever wanted to use a label, but I'd leave it in for clarity.)


The typesetting of the radio button itself also adds some spaces, too. This is done by \@@Radio, which adds several \spaces. We can prevent this by locally making \space do nothing (using etoolbox):

\pretocmd\@@Radio{\begingroup\let\space\@empty}{}{}
\apptocmd\@@Radio{\endgroup}{}{}

I do not know if this might have any unintended consequences, but I can't think of any right now.


All in all your MWE now looks like this:

\documentclass{report}

\usepackage{etoolbox}

\usepackage{array}
\usepackage{hyperref}

\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\makeatletter
    \renewcommand*\LayoutChoiceField[2]{#1#2}
    \pretocmd\@@Radio{\begingroup\let\space\@empty}{}{}
    \apptocmd\@@Radio{\endgroup}{}{}
\makeatother

\begin{document}
\begin{Form}

\noindent\begin{table}[!h]
  \begin{tabular} {|m{8cm}|C{0.75cm}|C{0.75cm}|C{1.5cm}|}
    \cline{2-4}
    \multicolumn{1}{c|}{} &
    Yes & No & Maybe \\
    \hline
    Some question? &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=yes} &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=no} &
    \ChoiceMenu[ name=Q1, radio, radiosymbol= ]{}{=maybe} \\
    \hline
    Some other question? &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=yes} &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=no} &
    \ChoiceMenu[ name=Q2, radio, radiosymbol= ]{}{=maybe} \\
    \hline
  \end{tabular}
\end{table}

\end{Form}
\end{document}

MWE output

2
  • Thanks. This improves the result by a few pixel. However, the radio fields are still not quite center-aligned screenshot.
    – Sirko
    May 1 '19 at 16:53
  • Looks like I didn't check the result carefully enough. I edited my answer accordingly.
    – schtandard
    May 1 '19 at 17:34

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.