我必须承认我是乳胶新手。我正在尝试创建一个乳胶表,其中每个单元格都有十进制数字符号和一些星号。使用我上面分享的代码,我无法以良好的方式对齐它们。表格看起来很糟糕。
有没有办法让它们对齐并看起来更美观?提前致谢。
这是我的代码和表格:
\begin{table}[t!]
%\small
\setlength{\tabcolsep}{2pt}
\begin{tabular}{lccccc@{}}
\toprule
& & MMM & NNN & ATTT & PRS \\ \midrule
\multirow{2}{*}{X} & Coef & -0.010$^{*}$ & -0.010$^{*}$ & -0.002 & 0.001 \\
& AAA & 0.080 & 0.082 & 0.010 & 0.018 \\
\multirow{2}{*}{Y} & Coef & 0.006 & 0.002 & 0.001 & -0.003$^{***}$ \\
& AAA & 0.037 & 0.003 & 0.020 & 0.523 \\
\multirow{2}{*}{Z} & Coef & 0.005 & 0.001 & 0.001$^{*}$ & 0.001 \\
& AAA & 0.049 & 0.070 & 0.070 & 0.014 \\
\multirow{2}{*}{T} & Coef & 0.016 & 0.019 & 0.015 & -0.001 \\
& AAA & 0.023 & 0.029 & 0.073 & 0.048 \\ \midrule
\multicolumn{2}{l}{Model Fit (R2)} & 0.19 & 0.17 & 0.17 & 0.60 \\ \bottomrule
\end{tabular}
\end{table}
答案1
您可以使用siunitx
来将数字与小数点对齐。我还提供了第二个示例表,其布局略有不同,不使用\multirow
:
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\begin{table}
\sisetup{table-format = -1.3, table-space-text-post=$^{*}$}
\begin{tabular}{llSSSS[table-space-text-post=$^{***}$]}
\toprule
& & {MMM} & {NNN} & {ATTT} & {PRS} \\ \midrule
\multirow{2}{*}{X} & Coef & -0.010$^{*}$ & -0.010$^{*}$ & -0.002 & 0.001 \\
& AAA & 0.080 & 0.082 & 0.010 & 0.018 \\
\multirow{2}{*}{Y} & Coef & 0.006 & 0.002 & 0.001 & -0.003$^{***}$ \\
& AAA & 0.037 & 0.003 & 0.020 & 0.523 \\
\multirow{2}{*}{Z} & Coef & 0.005 & 0.001 & 0.001$^{*}$ & 0.001 \\
& AAA & 0.049 & 0.070 & 0.070 & 0.014 \\
\multirow{2}{*}{T} & Coef & 0.016 & 0.019 & 0.015 & -0.001 \\
& AAA & 0.023 & 0.029 & 0.073 & 0.048 \\ \midrule
\multicolumn{2}{l}{Model Fit (R2)} & 0.19 & 0.17 & 0.17 & 0.60 \\ \bottomrule
\end{tabular}
\end{table}
\begin{table}
\sisetup{table-format = -1.3, table-space-text-post=$^{*}$}
\begin{tabular}{llSSSS[table-space-text-post=$^{***}$]}
\toprule
& & {MMM} & {NNN} & {ATTT} & {PRS} \\ \midrule
X & Coef & -0.010$^{*}$ & -0.010$^{*}$ & -0.002 & 0.001 \\
& AAA & 0.080 & 0.082 & 0.010 & 0.018 \\ \addlinespace
Y & Coef & 0.006 & 0.002 & 0.001 & -0.003$^{***}$ \\
& AAA & 0.037 & 0.003 & 0.020 & 0.523 \\ \addlinespace
Z & Coef & 0.005 & 0.001 & 0.001$^{*}$ & 0.001 \\
& AAA & 0.049 & 0.070 & 0.070 & 0.014 \\ \addlinespace
T & Coef & 0.016 & 0.019 & 0.015 & -0.001 \\
& AAA & 0.023 & 0.029 & 0.073 & 0.048 \\ \midrule
\multicolumn{2}{l}{Model Fit (R2)} & 0.19 & 0.17 & 0.17 & 0.60 \\ \bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
\sisetup{table-format = -1.3}
\begin{table}[t!]
%\small
\setlength{\tabcolsep}{2pt}
\begin{tabular}{lcSSSS@{}}
\toprule
& & MMM & NNN & ATTT & PRS \\ \midrule
\multirow{2}{*}{X} & Coef & -0.010$^{*}$ & -0.010$^{*}$ & -0.002 & 0.001 \\
& AAA & 0.080 & 0.082 & 0.010 & 0.018 \\
\multirow{2}{*}{Y} & Coef & 0.006 & 0.002 & 0.001 & -0.003$^{***}$ \\
& AAA & 0.037 & 0.003 & 0.020 & 0.523 \\
\multirow{2}{*}{Z} & Coef & 0.005 & 0.001 & 0.001$^{*}$ & 0.001 \\
& AAA & 0.049 & 0.070 & 0.070 & 0.014 \\
\multirow{2}{*}{T} & Coef & 0.016 & 0.019 & 0.015 & -0.001 \\
& AAA & 0.023 & 0.029 & 0.073 & 0.048 \\ \midrule
\multicolumn{2}{l}{Model Fit (R2)} & 0.19 & 0.17 & 0.17 & 0.60 \\ \bottomrule
\end{tabular}
\end{table}