0

I want to include images in my tabularx such that they are vertically centered, so I used code from Issue with vertical align image in table cell

That works fine, except that when I add the siunitx package to that example it fails with Error:(7) Argument of \Gin@ii has an extra }.

MWE:

\documentclass{article}
\usepackage[export,demo]{adjustbox}
\usepackage{cellspace} % [Edit] This provides the S column type for extra vertical space
\usepackage{siunitx} % Also provides the S column type for aligning decimal digits

\begin{document}
    \begin{tabular}{|Sc|}
        \includegraphics[valign=c]{test} \\
    \end{tabular}
\end{document}

Because the MWE itself is not my original problem, this is my full problem which should vertically center images, and which is exactly the answer I mentioned but with the siunitx package added (I need the siunitx package):

\documentclass{scrreprt}
\usepackage[export, demo]{adjustbox}    % in real document delete option "demo"
% adjustbox call "graphicx"
% "adjustbox" call "graphicx" plus add many function
% for manipulating boxes, among them here is used "valign"
\usepackage{cellspace,                  % for adding vertical space around cells' contents
tabularx}
\setlength\cellspacetoplimit{4pt}
\setlength\cellspacebottomlimit{4pt}
\renewcommand\tabularxcolumn[1]{m{#1}}  % for vertical centering of X cell contents
\usepackage{ragged2e}
\usepackage{siunitx}

\begin{document}
    \begin{table}[htb]
        \centering
        \setkeys{Gin}{width=11mm,height=11mm}   % with real images should be sufficient defined only image width
        %
        \begin{tabularx}{\linewidth}{|Sc|l|>{\RaggedRight}X|} % "S" add vertical space in column "c"
            \hline
            \textbf{Menu item}  & \textbf{Caption}  & \textbf{Description} \\
            \hline
            \includegraphics[valign=c]{security_unlock.png}% "valing=c" move baseline of the image to its middle
            & Login             & Show the login screen, where
            the user should enter his
            credentials to log on to the
            system.               \\
            \hline
            \includegraphics[valign=c]{security_lock.png}%
            & Logoff            & Log off the current user. A
            prompt will be shown where
            the user has to confirm the
            log off procedure.    \\
            \hline
            \includegraphics[valign=c]{employees-gear.png}%
            & Manage            & Opens a formular where the
            user can manage the user
            groups and users.     \\
            \hline
        \end{tabularx}
    \end{table}
\end{document}

Output:

main.tex:40: Argument of \Gin@ii has an extra }.
<inserted text> 
                \par 
l.40         \end{tabularx}
                           
Runaway argument?
val\bool_if:NT \l__siunitx_table_math_bool {\scan_stop: \c_math_toggle_token \E
TC.

MiKTeX 4.0.1, siunitx version 26-02-2020, adjustbox 30-08-2020, all packages up to date (and also happens on an up-to-date TeX Live).

1

You can solve your problem with load cellspace package as

\usepackage[column=O]{cellspace}

as suggested @ Ulrike Fischer in her comment, and then determine table as

\begin{tabularx}{\linewidth}{|Oc|l|>{\RaggedRight}X|} % "O" add vertical space in column "c"

However, you can insert images in table ba use of adjustbox, which is already loaded, capability to add margins around image by use of parameter margin. In this case you can remove cellspace stuff from document preamble:

\documentclass{scrreprt}
\usepackage[demo,               % in real document delete option "demo"
            export]{adjustbox}  % "adjustbox" call "graphicx" plus add many function
                                % for manipulating boxes, among them here is used "valign"
\usepackage{tabularx}
\usepackage{ragged2e}
\usepackage{siunitx}

\begin{document}
    \begin{table}[htb]
    \centering
    \renewcommand\tabularxcolumn[1]{m{#1}}  % for vertical centering of X cell contents
    \adjustboxset{width=11mm, height=11mm,valign=c, margin=0pt 3pt 0pt 3pt}
\begin{tabularx}{\linewidth}{|c|l|>{\RaggedRight}X|} % "S" add vertical space in column "c"
    \hline
\textbf{Menu item}  & \textbf{Caption}  & \textbf{Description}  \\
    \hline
\adjustimage{}{security_unlock.png}% 
    & Login         & Show the login screen, 
                      where the user should enter his
                      credentials to log on to the system.      \\
    \hline
\adjustimage{}{security_lock.png}%
    & Logoff        & Log off the current user. A prompt will be 
                      shown where the user has to confirm the
                      log off procedure.                        \\
    \hline
\adjustimage{}{employees-gear.png}%
    & Manage        & Opens a formular where the user can manage 
                      the user groups and users.     \\
    \hline
\end{tabularx}
    \end{table}
\end{document}

enter image description here

  • I think you meant to type Oc instead of =c in that first solution. This is a great alternative, actually even better because I don't need to change the column type at all, thanks! – PHPirate Dec 1 '20 at 6:40
  • @PHPirate, you are right! I miss the key on keyboard :-( – Zarko Dec 1 '20 at 6:43
2

you should protect material that siunitx should not align at the decimal number in S-columns by adding braces:

\documentclass{article}
\usepackage[export,demo]{adjustbox}
\usepackage{siunitx}

\begin{document}
    \begin{tabular}{|Sc|}
        {\includegraphics[valign=c]{example-image}} \\
    \end{tabular}
\end{document}
  • Ah, I see now that the siunitx package also defines the S column type and with that overrides the behaviour I need (the extra vertical space), that's a pity. – PHPirate Nov 30 '20 at 17:41
  • sorry I hadn't seen the cellspace reference, use \usepackage[column=O]{cellspace} to get a different name for its column type. – Ulrike Fischer Nov 30 '20 at 17:44
  • That was my mistake, I had incorrectly left it out of the MWE. That fixes it, thanks! – PHPirate Nov 30 '20 at 17: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.