我正在尝试右对齐多列表格标题,其中它跨越的列之一使用 dcolumn 在小数点上对齐,而另一列则左对齐。在下面的示例中,我希望“差异(p 值)”的右括号与其下方列的右括号齐平。我摆弄了列之间的间距,并创造性地混合了一般对齐方式“rcl”等。有人有其他提示吗?
\documentclass{article}
\usepackage{dcolumn}
\newcolumntype{Q}{D{.}{.}{2}}
\begin{document}
\begin{tabular}{lQQQ@{\hspace{0.1em}}l}
\hline
Variable & \multicolumn{1}{c}{Period 1} & \multicolumn{1}{c}{Period 2} & \multicolumn{2}{r}{Difference (p-value)} \\
\hline
var0 & 6.00 & 8.00 & 2.00 & (0.00) \\
var1 & 0.61 & 0.73 & 0.12 & (0.00) \\
var2 & 359.00 & 404.00 & 44.43 & (0.03) \\
\hline
\end{tabular}
\end{document}
答案1
猜测一下你喜欢什么(使用包siunitx
而不是dcolumn
):
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{l*{2}{S[table-format=3.2]}
S[table-format=2.2(1),
table-alignment=right,
separate-uncertainty,
]
}
\hline
Variable & {Period 1} & {Period 2} & {Difference (p-value)} \\
\hline
var0 & 6.00 & 8.00 & 2.00(0) \\
var1 & 0.61 & 0.73 & 0.12(0) \\
var2 & 359.00 & 404.00 & 44.43(3) \\
\hline
\end{tabular}
\bigskip
\begin{tabular}{l*{2}{S[table-format=3.2]}
S[table-format=2.2(1),
table-alignment=right,
]
}
\hline
Variable & {Period 1} & {Period 2} & {Difference (p-value)} \\
\hline
var0 & 6.00 & 8.00 & 2.00(0) \\
var1 & 0.61 & 0.73 & 0.12(0) \\
var2 & 359.00 & 404.00 & 44.43(3) \\
\hline
\end{tabular}
\bigskip
\begin{tabular}{l*{2}{S[table-format=3.2]}
S[table-format=8.0,
]
%@{\hskip-2em}
S[table-format=1.2,
table-space-text-pre=\,(,
table-space-text-post=),
input-symbols = {( )}
]
}
\hline
Variable & {Period 1} & {Period 2} & \multicolumn{2}{r}{Difference (p-value)} \\
\hline
var0 & 6.00 & 8.00 & 2.00 & (0.00) \\
var1 & 0.61 & 0.73 & 0.12 & (0.00) \\
var2 & 359.00 & 404.00 & 44.43 & (0.03) \\
\hline
\end{tabular}
\end{document}
前两个例子中的符号正确。
但是,我会将 p 值写为单独的列:
\documentclass{article}
\usepackage{siunitx}
\begin{document}
\begin{tabular}{l *{2}{ S[table-format=3.2] }
S[table-format=2.2]
S[table-format=1.2,
table-space-text-pre={\,(},
table-space-text-post=),
input-symbols = {( )}]
}
\hline
Variable & {Period 1} & {Period 2} & {Difference} & {(p-value)} \\
\hline
var0 & 6.00 & 8.00 & 2.00 & (0.00) \\
var1 & 0.61 & 0.73 & 0.12 & (0.00) \\
var2 & 359.00 & 404.00 & 44.43 & (0.03) \\
\hline
\end{tabular}
\end{document}