我正在尝试使用 tabu 制作表格,并使用 sunitx 包对齐和舍入表格中的条目。但是我不断收到以下错误:
!siunitx 错误:“未知选项”!!未知选项‘m’。!!有关更多信息,请参阅 siunitx 文档。
我的 MNWE(最小不工作示例)
\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage[]{xcolor}
\begin{document}
\newcolumntype Z{ XS[m,
tight-spacing=true,round-mode=places,
round-precision=2] }
\begin{table}
\centering
\small
\caption{Caption}\label{tab:exAll}
\begin{tabu}{X[m,l] ZZZZZZZZ}
\toprule
{}&{A}&{B}&{C}&{D}&{E}&{F}&{G}&{H}\\
\midrule
case 1&0.038941& 10.793553& 10.793553& 2.660292& 5.364928& 0.287945& 4.950661& 1.017396\\
case 2&0.051109& 10.416524&10.416524& 2.699890&5.236410& 0.348350& 5.528117& 0.835394\\
case 3&0.042755& 11.165675&11.165675& 2.845072& 6.585281& 0.279750& 5.059948& 0.920121\\
case 4&0.043165& 10.820561 &10.820561& 2.708484& 5.250033& 0.291793& 4.661221& 0.879731\\
case 5&0.042951&13.764616&13.764616& 2.643305& 5.608317& 0.278537& 5.080898& 0.871181\\
case 6&0.042078& 10.909180 &10.909180& 2.568346& 5.198260& 0.311224& 4.724302& 0.862366\\
\bottomrule
\end{tabu}
\end{table}
\end{document}
我该如何解决这个问题?我在 tex.se 上查看了类似的问题,但这些问题对我没有帮助。我希望我没有忽略一些非常简单的事情。
答案1
将新列定义更改为
\newcolumntype{Z}{S[
tight-spacing=true,round-mode=places,
round-precision=2] }
完整代码:
\documentclass[a4paper]{scrreprt}
\usepackage{siunitx,booktabs}
\usepackage{tabu}
\usepackage[]{xcolor}
\begin{document}
\newcolumntype{Z}{S[
tight-spacing=true,round-mode=places,
round-precision=2] }
\begin{table}
\centering
\small
\caption{Caption}\label{tab:exAll}
\begin{tabu}{X[m,l] ZZZZZZZZ}
\toprule
{}&{A}&{B}&{C}&{D}&{E}&{F}&{G}&{H}\\
\midrule
case 1&0.038941& 10.793553& 10.793553& 2.660292& 5.364928& 0.287945& 4.950661& 1.017396\\
case 2&0.051109& 10.416524&10.416524& 2.699890&5.236410& 0.348350& 5.528117& 0.835394\\
case 3&0.042755& 11.165675&11.165675& 2.845072& 6.585281& 0.279750& 5.059948& 0.920121\\
case 4&0.043165& 10.820561 &10.820561& 2.708484& 5.250033& 0.291793& 4.661221& 0.879731\\
case 5&0.042951&13.764616&13.764616& 2.643305& 5.608317& 0.278537& 5.080898& 0.871181\\
case 6&0.042078& 10.909180 &10.909180& 2.568346& 5.198260& 0.311224& 4.724302& 0.862366\\
\bottomrule
\end{tabu}
\end{table}
\end{document}
有了round-precision=3
,你就会得到
答案2
请注意,在这个解决方案中(与另一个),每列的数字均对齐且居中。
\documentclass{scrreprt}
\usepackage{booktabs}
\usepackage{siunitx}
\sisetup{
% locale = DE, % comma as decimal separator
tight-spacing = true,
round-mode = places
}
\def\precision{2} % change this value to suit your needs
\newcolumntype{Y}{S[table-format = 2.\precision, round-precision = \precision]}
\newcolumntype{Z}{S[table-format = 1.\precision, round-precision = \precision]}
\begin{document}
\begin{table}[htbp]
\centering
\small
\caption{An extremely relevant caption.}
\label{tab:exAll}
\begin{tabular}{l @{\qquad} Z *{2}{Y} *{5}{Z}}
\toprule
& {A} & {B} & {C} & {D} & {E} & {F} & {G} & {H} \\
\midrule
Case~1 & 0.038941 & 10.793553 & 10.793553 & 2.660292 & 5.364928 & 0.287945 & 4.950661 & 1.017396 \\
Case~2 & 0.051109 & 10.416524 & 10.416524 & 2.699890 & 5.236410 & 0.348350 & 5.528117 & 0.835394 \\
Case~3 & 0.042755 & 11.165675 & 11.165675 & 2.845072 & 6.585281 & 0.279750 & 5.059948 & 0.920121 \\
Case~4 & 0.043165 & 10.820561 & 10.820561 & 2.708484 & 5.250033 & 0.291793 & 4.661221 & 0.879731 \\
Case~5 & 0.042951 & 13.764616 & 13.764616 & 2.643305 & 5.608317 & 0.278537 & 5.080898 & 0.871181 \\
Case~6 & 0.042078 & 10.909180 & 10.909180 & 2.568346 & 5.198260 & 0.311224 & 4.724302 & 0.862366 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
您所要做的就是选择值\precision
,表格就会自动排版正确。