我有以下 MWE:
\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{tabularx}
\usepackage{array}
\usepackage{caption}
\usepackage{booktabs, siunitx}
\usepackage{dcolumn}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[h!]
\begin{scriptsize}
\centering
\caption{Caption}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.10}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{3}{D{.}{.}{6}}}
\toprule
& \mcc[1]{Col A}
& \mcc[1]{Col B}
& \mcc[1]{Col C} \\
\midrule
\multicolumn{4}{l}{\textbf{Panel A: This is model 1}}\\
\midrule
ABC &-1.23^{***} &-6.12 &-4.32^{*}\\
&(-9.01) &(-3.32) &(6.12)
\\
DEF &-4.12 &7.01 &-0.71\\
&(1.54) &(0.02) &(-1.52)
\\
\multicolumn{4}{l}{\textbf{Panel B: This is model 2 that has a longer name than model 1}}\\
\midrule
ABC &-0.64^* &-0.52 &-6.01^{**}\\
&(-1.86) &(-7.13) &(-9.43) \\
DEF &-0.23 &0.01 &-6.71 \\
&(-0.43) &(3.12) &(-3.52)\\
\bottomrule
\end{tabular*}
\end{scriptsize}
\end{table}
\end{document}
我对此表的唯一问题是列标签与条目不对齐,请参见下面的标记:
我注意到这是因为标题Panel B: This is model 2 that has a longer name than model 1
太长。有没有办法保留标题原样,但将条目与列名对齐Col C
?
答案1
tabularx
这与您使用的标准无关tabular*
。
我个人会tabular
在这里使用,因为强制表格全宽只会使列之间的距离更大,表格更难阅读(对于任何表格来说,这几乎都是这种情况)
但如果你确实希望表格占满整个宽度,你可以隐藏跨越条目的宽度,这样宽度就会在每列之间平均分配
\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
% not used \usepackage{tabularx}
\usepackage{array}
\usepackage{caption}
\usepackage{booktabs, siunitx}
\usepackage{dcolumn}
\NewExpandableDocumentCommand\mcc{O{1}m}
{\multicolumn{#1}{c}{#2}}
\begin{document}
\begin{table}[htp]% only use ! and h in very special "after all editing complete" emergency situations
\begin{scriptsize}
\centering
\caption{Caption}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.10}
\begin{tabular*}{\linewidth}{l @{\extracolsep{\fill}}*{3}{D{.}{.}{6}}}
\toprule
& \mcc[1]{Col A}
& \mcc[1]{Col B}
& \mcc[1]{Col C} \\
\midrule
\multicolumn{4}{l}{\rlap{\textbf{Panel A: This is model 1}}}\\
\midrule
ABC &-1.23^{***} &-6.12 &-4.32^{*}\\
&(-9.01) &(-3.32) &(6.12)
\\
DEF &-4.12 &7.01 &-0.71\\
&(1.54) &(0.02) &(-1.52)
\\
\multicolumn{4}{l}{\rlap{\textbf{Panel B: This is model 2 that has a longer name than model 1}}}\\
\midrule
ABC &-0.64^* &-0.52 &-6.01^{**}\\
&(-1.86) &(-7.13) &(-9.43) \\
DEF &-0.23 &0.01 &-6.71 \\
&(-0.43) &(3.12) &(-3.52)\\
\bottomrule
\end{tabular*}
\end{scriptsize}
\end{table}
\end{document}
答案2
和tabularx
:
\documentclass[12pt, a4paper]{article}
\usepackage[english]{babel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{booktabs, tabularx}
\NewExpandableDocumentCommand\mcx{O{1}m}
{\multicolumn{#1}{>{\centering\arraybackslash}X}{#2}}
\NewExpandableDocumentCommand\mclbf{O{1}m}
{\multicolumn{#1}{>{\bfseries}l}{#2}}
\usepackage{caption}
\usepackage{siunitx}
\begin{document}
\begin{table}[ht]
\sisetup{input-open-uncertainty= ,
input-close-uncertainty= ,
table-space-text-pre=(,
table-space-text-post=***,
table-format=-1.2}
\centering
\caption{Caption}
\renewcommand{\arraystretch}{1.10}
\begin{tabularx}{\linewidth}{ l *{3}{S} }
\toprule
& \mcx{Col A} & \mcx{Col B}
& \mcx{Col C} \\
\midrule
\mclbf[4]{Panel A: This is model 1} \\
\midrule
ABC & -1.23$^{***}$ & -6.12 & -4.32$^{*}$ \\
& (-9.01) & (-3.32) & (6.12) \\
DEF & -4.12 & 7.01 & -0.71 \\
& (1.54) & (0.02) & (-1.52) \\
\mclbf[4]{Panel B: This is model 2
that has a longer name than model 1} \\
\midrule
ABC & -0.64$^{*}$ & -0.52 & -6.01$^{**}$ \\
& (-1.86) & (-7.13) & (-9.43) \\
DEF & -0.23 & 0.01 & -6.71 \\
& (-0.43) & (3.12) & (-3.52) \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}