我有一张表格,需要按小数点对齐数字。之后,我需要向左对齐五列(在下面的示例中从Country
到),但向右对齐最后一列( )。我知道我需要使用包,但无法使其工作。任何帮助都将不胜感激!Robust S.E.
p-value
siunitx
代码:
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs, multirow, siunitx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{lllllr}
\toprule
{Country}& {Predictor} & {Estimate} & {Robust Z} & {Robust S.E.} & {p-value} \\
\midrule
\multirow{3}{*}{England}
& Intercept & 4.776 & 2.511 & 1.902 & 0.012\\
& Non-PIDS & 0.566 & 10.734 & 0.053 & $<$0.001\\
& PIDS & 0.280 & 5.184 & 0.054 & $<$0.001\\
\addlinespace
\multirow{3}{*}{Germany}
& Intercept & 9.638 & 4.114 & 2.343 & $<$0.001\\
& Non-PIDS & 0.473 & 6.439& 0.073 & $<$0.001\\
& PIDS & 0.203 & 3.505 & 0.058 & $<$0.001\\
\addlinespace
\multirow{3}{*}{Netherlands}
& Intercept & 11.997 & 5.793 & 2.071 & $<$0.001\\
& Non-PIDS & 0.460 & 7.048 & 0.065 & $<$0.001\\
& PIDS & 0.14 & 2.380 & & 0.017\\
\addlinespace
\multirow{3}{*}{Sweden}
& Intercept & 11.723 & 2.452 & 4.782 & $<$0.001\\
& Non-PIDS & 0.448 & 0.077 & 5.799 & $<$0.001\\
& PIDS & 0.176 & 0.054 & 3.232 & 0.001\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
带包的解决方案tabularray
。它使用库booktabs
和siunitx
模仿同名的包。
\begin{document}
\lipsum[1]
\begin{table}[ht]\centering
\caption{with \texttt{tabularray}.}
\begin{tblr}
{
colspec={llQ[si={table-format=2.3},l]
Q[si={table-format=2.3},l]
Q[si={table-format=1.3},l]
Q[si={table-format=<1.3},r]},
row{1}={guard},
row{4,7,10}={belowsep+=4pt}
}
\toprule
Country & Predictor & Estimate & Robust Z & Robust S.E. & p-value\\
\midrule
& Intercept & 4.776 & 2.511 & 1.902 & 0.012\\
England & Non-PIDS & 0.566 & 10.734 & 0.053 & <0.001\\
& PIDS & 0.280 & 5.184 & 0.054 & <0.001\\
%
& Intercept & 9.638 & 4.114 & 2.343 & <0.001\\
Germany & Non-PIDS & 0.473 & 6.439 & 0.073 & <0.001\\
& PIDS & 0.203 & 3.505 & 0.058 & <0.001\\
%
& Intercept & 11.997 & 5.793 & 2.071 & <0.001\\
Netherlands & Non-PIDS & 0.460 & 7.048 & 0.065 & <0.001\\
& PIDS & 0.14 & 2.380 & & 0.017\\
%
& Intercept & 11.723 & 2.452 & 4.782 & <0.001\\
Sweden & Non-PIDS & 0.448 & 0.077 & 5.799 & <0.001\\
& PIDS & 0.176 & 0.054 & 3.232 & <0.001\\
\bottomrule
\end{tblr}
\end{table}
\lipsum[2]
\end{document}
答案2
我不知道问题出在哪里。
我不会使用\multirow
,这会使表格变得更少,而不是更清晰。
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs,siunitx}
\begin{document}
\begin{table}[htp]
\centering
\begin{tabular}{
@{}
ll
S[table-format=2.3]
S[table-format=2.3]
S[table-format=1.3]
r
@{}
}
\toprule
Country& {Predictor} & {Estimate} & {Robust Z} & {Robust S.E.} & {p-value} \\
\midrule
England
& Intercept & 4.776 & 2.511 & 1.902 & 0.012\\
& Non-PIDS & 0.566 & 10.734 & 0.053 & $<$0.001\\
& PIDS & 0.280 & 5.184 & 0.054 & $<$0.001\\
\addlinespace
Germany
& Intercept & 9.638 & 4.114 & 2.343 & $<$0.001\\
& Non-PIDS & 0.473 & 6.439 & 0.073 & $<$0.001\\
& PIDS & 0.203 & 3.505 & 0.058 & $<$0.001\\
\addlinespace
Netherlands
& Intercept & 11.997 & 5.793 & 2.071 & $<$0.001\\
& Non-PIDS & 0.460 & 7.048 & 0.065 & $<$0.001\\
& PIDS & 0.14 & 2.380 & & 0.017\\
\addlinespace
Sweden
& Intercept & 11.723 & 2.452 & 4.782 & $<$0.001\\
& Non-PIDS & 0.448 & 0.077 & 5.799 & $<$0.001\\
& PIDS & 0.176 & 0.054 & 3.232 & 0.001\\
\bottomrule
\end{tabular}
\caption{Some caption to this table, don't forget it}
\end{table}
\end{document}
tabularray
请记住非常速度很慢,对于这样的表你确实不需要它。