siunitx 格式定义不生效

siunitx 格式定义不生效

有人能给我一点提示吗?我使用该包来对齐表格列中的数字。但是,表格格式定义似乎没有生效。例如,在 D 行中,减号和小于号似乎破坏了它。关于如何正确对齐这一点,有什么想法吗?

\begin{table}
\centering
\caption{a table.}  
\label{table:x}
\begin{scriptsize}
    \begin{tabular}
        {
            l
            l
            S[table-format = 2.2]
            S[table-format = 2.2]
            S[table-format = -1.2]
            S[table-format = 2]
            S[table-format = 0.2]
        }
        \toprule
        Dim                 &       Cond        & {\emph{M} (secs)}     & {\emph{SD}}           & {\emph{t}}                & {\emph{df}}                   & {\emph{p}}            \\          
        \midrule                
        \multirow{2}{*}{A}  &       B           & 49.50                 & 16.37                 & \multirow{2}{*}{0.03}     & \multirow{2}{*}{15}           & \multirow{2}{*}{.97}  \\
                            &       E           & 49.37                 & 14.89                 &                           &                               &                       \\  

        \midrule
        \multirow{2}{*}{B}  &       B           & 30.37                 & 10.85                 & \multirow{2}{*}{2.88}     & \multirow{2}{*}{15}           & \multirow{2}{*}{.01}  \\
                            &       E           & 24.18                 & 8.78                  &                           &                               &                       \\     

        \midrule
        \multirow{2}{*}{C}  &       B           & 9.12                  & 5.30                  & \multirow{2}{*}{2.38}     & \multirow{2}{*}{15}           & \multirow{2}{*}{.03}  \\
                            &       E           & 5.56                  & 3.36                  &                           &                               &                       \\                                              
        \midrule                                            
        \multirow{2}{*}{D}  &       B           & 0.18                  & 0.54                  & \multirow{2}{*}{-8.90}    & \multirow{2}{*}{15}           & \multirow{2}{*}{{<}.01} \\                    
                            &       E           & 11.50                 & 5.13                  &                           &                               &                       \\     

        \bottomrule
    \end{tabular}
\end{scriptsize}
\end{table}

例子

答案1

这只是对 @Zarko 的回答的评论以及我在这里的使用方式\tablenum。我在这里使用了三个不同的宏,以便不直接在列中添加格式。请注意最后三列的对齐方式如何不同。

\documentclass{article}
\usepackage{booktabs, multirow}
\usepackage{siunitx}
\usepackage[font=small, labelfont=bf, skip=1ex]{caption}

\begin{document}
\begin{table}
% placing these macros here as they are likely to jsut be used for this particular table
\newcommand\mrtnumA[1]{\multirow{2}{*}{\tablenum[table-format=-1.2]{#1}}}
\newcommand\mrtnumB[1]{\multirow{2}{*}{\tablenum[table-format=2.0]{#1}}}
\newcommand\mrtnumC[1]{\multirow{2}{*}{\tablenum[table-format=<1.2]{#1}}}
\centering
\caption{a table.}
\label{table:x}
%\scriptsize
    \begin{tabular}
        {
         *{2}{c}
         *{2}{S[table-format = 2.2]}
         *{3}{c}
        }
        \toprule
Dim                & Cond & {\emph{M} (secs)} & {\emph{SD}} & $t$             & $df$         & $p$             \\
        \midrule
\multirow{2}{*}{A} & B    & 49.50             & 16.37       & \mrtnumA{0.03}  & \mrtnumB{15} & \mrtnumC{.97}   \\
                   & E    & 49.37             & 14.89       &                 &              &                 \\
        \midrule
\multirow{2}{*}{B} & B    & 30.37             & 10.85       & \mrtnumA{2.88}  & \mrtnumB{15} & \mrtnumC{.01}   \\
                   & E    & 24.18             & 8.78        &                 &              &                 \\
        \midrule
\multirow{2}{*}{C} & B    & 9.12              & 5.30        & \mrtnumA{2.38}  & \mrtnumB{15} & \mrtnumC{.03}   \\ 
                   & E    & 5.56              & 3.36        &                 &              &                 \\
        \midrule
\multirow{2}{*}{D} & B    & 0.18              & 0.54        & \mrtnumA{-8.90} & \mrtnumB{15} & \mrtnumC{< .01} \\
                   & E    & 11.50             & 5.13        &                 &              &                 \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案2

  • 您没有提供完整的小文档,因此您的文档的序言和文档类别是未知的。因此表格标题的最终外观留给您。
  • 你所展示的表格是无法编译的(参见我上面的评论)
  • 以下可能的解决方案是重新设计列类型的情况

\documentclass{article}
\usepackage{booktabs, multirow}
\newcommand\mcm[1]{\multicolumn{1}{>{$}c<{$}}{#1}}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\caption{a table.}
\label{table:x}
%\scriptsize
    \begin{tabular}
        {
         *{2}{c}
         *{2}{S[table-format = 2.2]}
         *{3}{r}
        }
        \toprule
Dim & Cond  & {\emph{M} (secs)}
                    & {\emph{SD}}
                            & \mcm{t}   & \mcm{df}  & \mcm{p}           \\
    \midrule
\multirow{2}{*}{A}
    & B     & 49.50 & 16.37 & \multirow{2}{*}{0.03}
                                        & \multirow{2}{*}{15}
                                                    &  \multirow{2}{*}{.97}
                                            \\
    & E     & 49.37 & 14.89 &       &       &                           \\
        \midrule
\multirow{2}{*}{B}
    & B     & 30.37 & 10.85 & \multirow{2}{*}{2.88}
                                    & \multirow{2}{*}{15}
                                            & \multirow{2}{*}{.01}      \\
    & E     & 24.18 & 8.78  &       &       &                           \\
        \midrule
\multirow{2}{*}{C}
    & B     & 9.12  & 5.30  & \multirow{2}{*}{2.38}
                                    & \multirow{2}{*}{15}
                                            & \multirow{2}{*}{.03}      \\
    & E     & 5.56  & 3.36  &       &       &                           \\
        \midrule
\multirow{2}{*}{D}
    & B     & 0.18  & 0.54  & \multirow{2}{*}{$-8.90$}
                                    & \multirow{2}{*}{15}
                                            & \multirow{2}{*}{$< .01$}  \\
    & E     & 11.50 & 5.13  &       &       &                           \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

编辑:

考虑达莱夫在下面发表评论,您的表格可以格式化如下:

\documentclass{article}
\usepackage{booktabs, multirow}
\newcommand\mrtnum[1]{\multirow{2}{*}{\tablenum{#1}}}
\usepackage{siunitx}
\usepackage[font=small, labelfont=bf, skip=1ex]{caption}

\begin{document}
\begin{table}
\centering
\caption{a table.}
\label{table:x}
%\scriptsize
    \begin{tabular}
        {
         *{2}{c}
         *{2}{S[table-format = 2.2]}
         *{3}{c}
        }
        \toprule
Dim & Cond  & {\emph{M} (secs)}
                    & {\emph{SD}}
                            & $t$   & $df$  & $p$           \\
        \midrule
\multirow{2}{*}{A}
    & B     & 49.50 & 16.37 & \mrtnum{0.03}
                                    & \mrtnum{15}
                                            &  \mrtnum{.97} \\
    & E     & 49.37 & 14.89 &       &       &               \\
        \midrule
\multirow{2}{*}{B}
    & B     & 30.37 & 10.85 & \mrtnum{2.88}
                                    & \mrtnum{15}
                                            & \mrtnum{.01}  \\
    & E     & 24.18 & 8.78  &       &       &               \\
        \midrule
\multirow{2}{*}{C}
    & B     & 9.12  & 5.30  & \mrtnum{2.38}
                                    & \mrtnum{15}
                                            & \mrtnum{.03}  \\
    & E     & 5.56  & 3.36  &       &       &               \\
        \midrule
\multirow{2}{*}{D}
    & B     & 0.18  & 0.54  & \mrtnum{-8.90}
                                    & \mrtnum{15}
                                            & \mrtnum{< .01} \\
    & E     & 11.50 & 5.13  &       &       &               \\
        \bottomrule
    \end{tabular}
\end{table}
\end{document}

在此处输入图片描述

答案3

我认为你不应该使用\multirow它来理解表格:差异是计算出来的数据已读取。

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}
\begin{table}
\centering
\caption{a table.}
\label{table:x}
\begin{tabular}{
  l
  l
  S[table-format =  2.2]
  S[table-format =  2.2]
  S[table-format = -1.2]
  S[table-format =  2.0]
  S[table-format =  1.2,table-comparator=true]
}
\toprule
Dim & Cond  & {$M$ (\si{\sec})} & {$\mathit{SD}$} & {$t$} & {$df$} & {$p$} \\
\midrule
A & B & 49.50 & 16.37 \\
  & E & 49.37 & 14.89 &  0.03 & 15 &  0.97 \\
\addlinespace
B & B & 30.37 & 10.85 \\
  & E & 24.18 &  8.78 &  2.88 & 15 &  0.01 \\
\addlinespace
C & B &  9.12 &  5.30 \\
  & E &  5.56 &  3.36 &  2.38 & 15 &  0.03 \\
\addlinespace
D & B &  0.18 &  0.54 \\
  & E & 11.50 & 5.13  & -8.90 & 15 & <0.01 \\
\bottomrule
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

相关内容