当已经使用 cellspace 中的 S 列时使用 siunitx

当已经使用 cellspace 中的 S 列时使用 siunitx

我想在 tabularx 中包含图像,使它们垂直居中,所以我使用了代码表格单元格中垂直对齐图像的问题

一切正常,但当我将 siunitx 包添加到该示例时,它会失败Error:(7) Argument of \Gin@ii has an extra }.

梅威瑟:

\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}

因为 MWE 本身不是我原来的问题,所以我的完整问题应该是垂直居中图像,这正是答案我提到但是添加了 siunitx 包(我需要 siunitx 包):

\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}

输出:

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 版本 26-02-2020、adjustbox 30-08-2020,所有软件包均已更新(并且在最新的 TeX Live 上也发生)。

答案1

您可以使用加载cellspace包来解决您的问题

\usepackage[column=O]{cellspace}

正如 Ulrike Fischer 在她的评论中所建议的那样,然后确定表格为

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

但是,您可以使用adjustbox已加载的 向表格中插入图像,使用参数在图像周围添加边距的功能margin。在这种情况下,您可以cellspace从文档序言中删除内容:

\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}

在此处输入图片描述

答案2

您应该通过添加括号来保护 siunitx 不应在 S 列中的小数处对齐的材料:

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

\begin{document}
    \begin{tabular}{|Sc|}
        {\includegraphics[valign=c]{example-image}} \\
    \end{tabular}
\end{document}

相关内容