我正在尝试创建下表,但遇到有关该表的两个问题:
1- 表格中“.”前后的数字是不同的数字。我试图使用代码{l*{2}{S[table-format = 3.1]}}
来对齐数字,但失败了。对于这样的表格,我该如何实现十进制数字的对齐?(你能给出评论来解释代码吗?)
2- 有没有办法控制表格中每列的宽度?我尝试了 c{2cm},错误显示为“非法特征”。
\documentclass{article}
\usepackage{amsmath,amssymb,graphicx}
\usepackage{threeparttable}
\begin{document}
\begin{table}
\centering
\caption{The results on the datasets}
\begin{tabular}
{c|c|c|c|c}
\hline
{Methodology} & \multicolumn{2}{c|}{Data 1} & \multicolumn{2}{c}{Data 2} \\ \cline{2-5}
& mean $\pm$ std & p\_value & mean$\pm$ std & p\_value \\ \hline
method 1 & $1700.5\pm 200.91$ & $0.0\%$ & $-10000.2\pm800.0$ & $0.0\%$ \\
method 2 & $300.8\pm 100.0$ & $0.5\%$ & $-10002.18\pm 800.5$ & $0.0\%$ \\
method 3 & $-100.5\pm 200.2$ & $10.5\%$ & $-8006.8\pm 899.8$ & $0.0\%$ \\ Method 4 & $553.83 \pm 102.2$ & $0.1\%$ & $-20090.8\pm 300.1$ & $0.0\%$ \\
\hline
\end{tabular}
\end{table}
\end{document}
答案1
要排版一列与单独的不确定性相关的数字,您可以使用包
siunitx
,设置包选项separate-uncertainty
,删除$
内联数学启动符和终止符,然后将列类型设置为(例如)S[table-format=-3.2(3.2)]
。为了使列居中并且具有固定宽度(比如说) 2 厘米,请加载包
array
(另外:该array
包非常有用,因此许多其他包会array
自动加载该包),然后更改c
为w{c}{2cm}
。
请注意,我还选择通过省略所有垂直线并用包的画线宏替换\hline
和来使表格具有更开放的“外观” 。\cline
booktabs
\documentclass{article}
\usepackage{amsmath,amssymb,booktabs}
\usepackage[T1]{fontenc}
\usepackage[separate-uncertainty,group-minimum-digits=4]{siunitx}
\begin{document}
\begin{table}
\centering
\caption{Summary statistics for datasets\strut}
\begin{tabular}{@{} l S[table-format=-3.2(3.2)] S
S[table-format=-5.2(3.2)] S @{}}
\toprule
Methodology & \multicolumn{2}{c}{Data 1} & \multicolumn{2}{c@{}}{Data 2} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& {mean $\pm$ std} & {p\_value} & {mean$\pm$ std} & {p\_value} \\
\midrule
method 1 & 1700.5\pm 200.91 & 0.0\% & -10000.2 \pm 800.0 & 0.0\% \\
method 2 & 300.8\pm 100.0 & 0.5\% & -10002.18\pm 800.5 & 0.0\% \\
method 3 & -100.5\pm 200.2 & 10.5\% & -8006.8 \pm 899.8 & 0.0\% \\
method 4 & 553.83 \pm 102.2 & 0.1\% & -20090.8 \pm 300.1 & 0.0\% \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
\documentclass{article}
\usepackage{geometry}
\usepackage{siunitx}
\usepackage{booktabs}
\begin{document}
\begin{table}
\centering
\caption{The results on the datasets}
\sisetup{separate-uncertainty, table-column-width=3.25cm}
\begin{tabular}
{c|S[table-format=-3.2(3.2)]|S[table-format=2.1]|S[table-format=-5.2(3.2)]|S[table-format=1.1]|}
\hline
{Methodology} & \multicolumn{2}{c|}{Data 1} & \multicolumn{2}{c}{Data 2} \\ \cline{2-5}
& {\phantom{\num{-100.50}}\llap{mean} $\pm$ \rlap{std}\phantom{\num{200.91}}} & {p\_value (\%)} & {\phantom{\num{-10002.18}}\llap{mean} $\pm$ \rlap{std}\phantom{\num{800.50}}} & { p\_value (\%)} \\ \hline
method 1 & 1700.50(20091) & 0.0 & -10000.2(8000) & 0.0 \\
method 2 & 300.8(1000) & 0.5 & -10002.18(80050) & 0.0 \\
method 3 & -100.5(2002) & 10.5 & -8006.8(8998) & 0.0 \\
Method 4 & 553.83(1022) & 0.1 & -20090.8(3001) & 0.0 \\
\hline
\end{tabular}
\end{table}
\begin{table}
\centering
\caption{The results on the datasets}
\sisetup{separate-uncertainty}
\begin{tabular}
{cS[table-format=-3.2(3.2)]S[table-format=2.1]S[table-format=-5.2(3.2)]S[table-format=1.1]}
\toprule
{Methodology} & \multicolumn{2}{c}{Data 1} & \multicolumn{2}{c}{Data 2} \\ \cmidrule(lr){2-3} \cmidrule(lr){4-5}
& {\phantom{\num{-100.50}}\llap{mean} $\pm$ \rlap{std}\phantom{\num{200.91}}} & {p\_value (\%)} & {\phantom{\num{-10002.18}}\llap{mean} $\pm$ \rlap{std}\phantom{\num{800.50}}} & { p\_value (\%)} \\
\midrule
method 1 & 1700.50(20091) & 0.0 & -10000.2(8000) & 0.0 \\
method 2 & 300.8(1000) & 0.5 & -10002.18(80050) & 0.0 \\
method 3 & -100.5(2002) & 10.5 & -8006.8(8998) & 0.0 \\
Method 4 & 553.83(1022) & 0.1 & -20090.8(3001) & 0.0 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}