siunitx 无法包含组分隔符

siunitx 无法包含组分隔符

我正在使用 siunitx 包来格式化表格,但无法让它包含逗号来分隔千位。我还想让数字对齐,到目前为止,我的代码可以正常工作。我尝试移动 group-separator 选项并将其放在 sisetup 之后,但这也无济于事。

\documentclass{article}
\usepackage{booktabs,caption}
\captionsetup[table]{font=large}
\usepackage{adjustbox}
\usepackage[flushleft]{threeparttable}
\usepackage[group-separator = {,},
            group-four-digits]{siunitx} % centering in tables
\begin{document}
\begin{tabular}{l *{2}{S[table-format=4.3]} S[table-format=4.0]} \toprule \toprule
                    &\multicolumn{3}{c}{\textbf{Everyone}}\\
                    &\multicolumn{1}{c}{{Mean}}&\multicolumn{1}{c}{{Std.Dev.}}&\multicolumn{1}{l}{{Obs}}\\
\midrule
Some label       &       0.123&       0.123&        9999\\
Some label       &       0.123&       0.123&        9999\\
Some label          &       0.123&       0.123&        9999\\
Some label abc&       0.123&       0.123&        9999\\
Some label abc&    1234.123&    1234.123&        9999\\
Some label abc&    1234.123&    1234.123&         999\\
Some label abc&     123.123&     316.123&         999\\
\bottomrule \bottomrule
\end{tabular}
\end{document}

我的表格目前如下图所示。

在此处输入图片描述

答案1

我设法获得西班牙风格的 1234.12345 → 1.234,12345 的唯一方法是:

[group-separator= \text{.}]

\usepackage[spanish]{babel}
\usepackage[group-separator= \text{.}]{siunitx}

所以

\num{12345.6789}

生成:

在此处输入图片描述

因此,对于完整的文本:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8x]{inputenc}
\usepackage[spanish]{babel}
\usepackage{siunitx}

\sisetup{group-separator= \text{.},
         group-minimum-digits = 4,
         group-digits = integer}

\begin{document}
Prueba: \num{12345.6789}
\[
    \frac{\text{6500111.1234}}{\num{6500111.1234}}
\]
\[
    \sen\alpha = \frac{630,3}{\num{630,3}}\\
\]

\end{document}

在此处输入图片描述

答案2

当前版本siunitx不再存在group-four-digits(尽管group-four-digits=true仍然有效)。

使用较旧的 TeX 发行版(此处为 TeX Live 2020),

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage{adjustbox}
\usepackage[flushleft]{threeparttable}
\usepackage{siunitx} % centering in tables

\captionsetup[table]{font=large}

\sisetup{
  group-separator = {,},
  group-four-digits,
}

\begin{document}

\begin{table}
\centering

\caption{A caption}

\begin{tabular}{l *{2}{S[table-format=4.3]} S[table-format=4.0]}
\toprule
  &\multicolumn{3}{c}{\textbf{Everyone}}\\
  &\multicolumn{1}{c}{{Mean}}&\multicolumn{1}{c}{{Std.\ Dev.}}&\multicolumn{1}{l}{{Obs}}\\
\midrule
Some label     &       0.123&       0.123&        9999\\
Some label     &       0.123&       0.123&        9999\\
Some label     &       0.123&       0.123&        9999\\
Some label abc &       0.123&       0.123&        9999\\
Some label abc &    1234.123&    1234.123&        9999\\
Some label abc &    1234.123&    1234.123&         999\\
Some label abc &     123.123&     316.123&         999\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

\sisetup在加载包时建议使用传递选项。

使用当前的 TeX 发行版

\documentclass{article}
\usepackage{booktabs,caption}
\usepackage{adjustbox}
\usepackage[flushleft]{threeparttable}
\usepackage{siunitx} % centering in tables

\captionsetup[table]{font=large}

\sisetup{
  group-separator = {,},
  group-minimum-digits=4,
}

\begin{document}

\begin{table}
\centering

\caption{A caption}

\begin{tabular}{l *{2}{S[table-format=4.3]} S[table-format=4.0]}
\toprule
  &\multicolumn{3}{c}{\textbf{Everyone}}\\
  &\multicolumn{1}{c}{{Mean}}&\multicolumn{1}{c}{{Std.\ Dev.}}&\multicolumn{1}{l}{{Obs}}\\
\midrule
Some label     &       0.123&       0.123&        9999\\
Some label     &       0.123&       0.123&        9999\\
Some label     &       0.123&       0.123&        9999\\
Some label abc &       0.123&       0.123&        9999\\
Some label abc &    1234.123&    1234.123&        9999\\
Some label abc &    1234.123&    1234.123&         999\\
Some label abc &     123.123&     316.123&         999\\
\bottomrule
\end{tabular}

\end{table}

\end{document}

在此处输入图片描述

相关内容