使用 siunitx 表格类型 S 时表格单元格对齐不良

使用 siunitx 表格类型 S 时表格单元格对齐不良

我在使用 siunitx 包中的 S 表类型进行数字对齐时遇到了问题。数字没有居中,尤其是在右侧,数字超出了表格范围。该table-number-alignment选项无法按预期工作...

\documentclass{article}
\usepackage{rotating}
\usepackage{booktabs}
\usepackage{array,graphics}
\usepackage{siunitx}


\newcolumntype{R}[1]{%
>{\begin{turn}{90}\begin{minipage}{#1}%
\raggedright\hspace{0pt}}l%
<{\end{minipage}\end{turn}}%
}
\renewcommand{\arraystretch}{1.2} 
\begin{document}
\begin{table}
  \caption{bla..}
  \vspace{0.4em}
  \centering
  \label{tab:measurement}
  \sisetup{table-number-alignment = left, round-mode=places, round-precision=3
  } \footnotesize
    \begin{tabular}{@{}>{\raggedright\arraybackslash}m{2.54cm}*{9}{S}@{}}
      \toprule
      \multicolumn{1}{c}{Operation} &
      \multicolumn{1}{R{9em}}{Times executed} & 
      \multicolumn{1}{R{9em}}{Min Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Max Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Mean Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Standard Deviation Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Min Computing Time (s)} &
      \multicolumn{1}{R{9em}}{Max Computing Time (s)} &
      \multicolumn{1}{R{9em}}{Mean Computing Time (s)} &
      \multicolumn{1}{R{9em}}{Standard Deviation Computing Time (s)}\\
      \midrule
      Remove member from group & 14 &4480   &4480&  4480&   0&  15.15698&   94.44586&   26.47497429&    22.51140211\\
      Add member to group & 16397   &344&   344&    344&    0&  0.00484&    0.00484 &0.00484    &0\\
      \bottomrule
    \end{tabular}
\end{table}
\end{document}

答案1

我已对您的代码进行了以下两项修改

  • 更改R列类型,使其内容在相应列中居中

  • table-format为 9 列类型分配明确的选项S

在此处输入图片描述

\documentclass{article}
\usepackage{rotating} % rotating package loads graphicx package
\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx}

\newcolumntype{R}[1]{% add "\hfill" at start and end
>{\hfill\begin{turn}{90}\begin{minipage}{#1}%
\raggedright\hspace{0pt}}l%
<{\end{minipage}\end{turn}\hfill}%
}
\renewcommand{\arraystretch}{1.2} 
\begin{document}
\begin{table}
  \caption{bla..}
  \vspace{0.4em}
  \centering
  \label{tab:measurement}
  \sisetup{table-number-alignment = left, 
           round-mode = places, 
           round-precision = 3
  } 
  \footnotesize
    \begin{tabular}{@{} 
        >{\raggedright\arraybackslash}m{2.54cm}
        S[table-format=5.0,group-digits=false]
       *{3}{S[table-format=4.0]}
        S[table-format=1.0]
       *{4}{S[table-format=2.3]} @{}}
      \toprule
      Operation &
      \multicolumn{1}{R{9em}}{Times executed} & 
      \multicolumn{1}{R{9em}}{Min Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Max Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Mean Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Standard Deviation Traffic (Bytes)} &
      \multicolumn{1}{R{9em}}{Min Computing Time (s)} &
      \multicolumn{1}{R{9em}}{Max Computing Time (s)} &
      \multicolumn{1}{R{9em}}{Mean Computing Time (s)} &
      \multicolumn{1}{R{9.25em}}{Standard Deviation Computing Time (s)}\\
      \midrule
      Remove member from group & 14 &4480   &4480&  4480&   0&  15.15698&   94.44586&   26.47497429&    22.51140211\\
      Add member to group & 16397   &344&   344&    344&    0&  0.00484&    0.00484 &0.00484    &0\\
      \bottomrule
    \end{tabular}
\end{table}
\end{document}

相关内容