我试图将以下回归输出表中的值按 1000 欧元标记(逗号)对齐。但是,也有一些低于 1000 欧元的值没有按我希望的方式对齐(在它们上面和下面的逗号的右侧)。有没有办法将它们与其余值对齐,尽管这些值缺少逗号?
\documentclass[12pt]{article}
\usepackage{booktabs, caption, dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\begin{document}
\begin{table} \centering
\caption{Regression Results}
\begin{tabular}{l*{2}{d{3.6}} }
\toprule
\multicolumn{1}{l}{Groups} & \multicolumn{1}{c}{$1^{st}$} & \multicolumn{1}{c}{$1^{st}$} \\
\midrule
Intercept & -32,332 & -66,459^{***} \\
& (17,820) & (21,006) \\
Income & 340 & 870^{*} \\
& (240) & (340) \\
Experience & 747^{*} & 818 \\
& (372) & (469) \\
HH Type & 5,984 & 24,189 \\
& (12,499) & (15,894) \\
\midrule
\multicolumn{1}{l}{R$^{2}$} & \multicolumn{1}{c}{0.07} & \multicolumn{1}{c}{0.20} \\
\multicolumn{1}{l}{N} & \multicolumn{1}{c}{299} & \multicolumn{1}{c}{299} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
以下是我使用该siunitx
包来对齐数字的建议:
\documentclass[12pt]{article}
\usepackage{booktabs, caption, dcolumn}
\newcolumntype{d}[1]{D{,}{,}{#1}}
\usepackage{siunitx}
\sisetup{
group-digits = true,
group-minimum-digits = 4,
group-separator = {,},
table-align-text-pre = false,
table-align-text-post = false,
input-open-uncertainty = ,
input-close-uncertainty = ,
table-space-text-post = $^{***}$,
table-space-text-pre = {(},
}
\begin{document}
\begin{table} \centering
\caption{Regression Results}
\begin{tabular}{l*{2}{S[table-format=-5]} }
\toprule
Groups & {$1^{st}$} & {$1^{st}$} \\
\midrule
Intercept & -32332 & -66459$^{***}$ \\
& (17820) & (21006) \\
Income & 340 & 870$^{*}$\\
& (240) & (340) \\
Experience & 747$^{*}$ & 818 \\
& (372) & (469) \\
HH Type & 5984 & 24189 \\
& (12499) & (15894) \\
\midrule
R$^{2}$ & {0.07} & {0.20}\\
N & {299} & {299} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
请注意,我手动删除了表格中数字的千位分隔符。如果您想在代码中保留它们,您可能需要将其添加input-ignore={,},input-decimal-markers={.}
到\sisetup
命令中。