如下面的代码所示,我有一个包含两个面板的表格,每个面板的列数不同。我希望面板 B 的列相对于面板 A 均匀分布。目前,我无法将面板 B 的列与面板 A 对齐。我该怎么做?
\documentclass[twoside, a4paper, 12pt]{article}
\usepackage{booktabs,tabularx}
\usepackage[font=bf, labelsep=none, singlelinecheck=false]{caption}
\usepackage[english]{babel}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{dcolumn}
\begin{document}
\begin{table}[H]
\footnotesize
\setlength\tabcolsep{3pt}
\begin{center}
\caption{\\ \fontsize{10pt}{12pt}\selectfont \normalfont Here's a title for the table.
}
\noindent\makebox[\textwidth]{
\begin{tabular}{@{}l *{13}{D{.}{.}{4}}@{}}
\multicolumn{4}{l}{Panel A. Here's a title} & & & & & & & & & & \\
\toprule
\multicolumn{1}{l}{} & \multicolumn{6}{c}{Subtitle here} & \multicolumn{7}{c}{Subtitle here} \\
\cmidrule(l){2-7} \cmidrule(l){8-14}
\multicolumn{1}{l}{} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{$<$10\%} & \multicolumn{1}{c}{10-30\%} & \multicolumn{1}{c}{30-50\%} & \multicolumn{1}{c}{50-70\%} & \multicolumn{1}{c}{$>$70\%} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{$<$10\%} & \multicolumn{1}{c}{10-20\%} & \multicolumn{1}{c}{20-30\%} & \multicolumn{1}{c}{30-40\%} & \multicolumn{1}{c}{40-50\%} & \multicolumn{1}{c}{$>$50\%} \\
\midrule
\multicolumn{1}{l}{group 1} & \multicolumn{1}{c}{0.228} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{11} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.056} & \multicolumn{1}{c}{16} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} \\
\multicolumn{1}{l}{group 2} & \multicolumn{1}{c}{0.343} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{9} & \multicolumn{1}{c}{9} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.126} & \multicolumn{1}{c}{12} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{1} \\
\multicolumn{1}{l}{group 3} & \multicolumn{1}{c}{0.495} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{15} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{1} & \multicolumn{1}{c}{0.212} & \multicolumn{1}{c}{8} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{4} \\
\multicolumn{1}{l}{group 4} & \multicolumn{1}{c}{0.639} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{6} & \multicolumn{1}{c}{10} & \multicolumn{1}{c}{0.258} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{4} \\
\multicolumn{1}{l}{group 5} & \multicolumn{1}{c}{0.747} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{3} & \multicolumn{1}{c}{14} & \multicolumn{1}{c}{0.260} & \multicolumn{1}{c}{2} & \multicolumn{1}{c}{6} & \multicolumn{1}{c}{5} & \multicolumn{1}{c}{4} & \multicolumn{1}{c}{0} & \multicolumn{1}{c}{3} \\
\midrule
\multicolumn{6}{l}{Panel B. Here's a slightly longer title} & & & & & & & & \\
\midrule
\multicolumn{2}{l}{} & \multicolumn{2}{c}{$\widehat{\alpha}$ ($p$-value)} & \multicolumn{2}{c}{$\widehat{\sigma}_{\varepsilon}$} & \multicolumn{2}{c}{IR} & \multicolumn{1}{c}{$\widehat{\beta}^{m}$} & \multicolumn{1}{c}{$\widehat{\beta}^{s}$} & \multicolumn{1}{c}{$\widehat{\beta}^{h}$} & \multicolumn{1}{c}{$\widehat{\beta}^{u}$} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{Std. Dev.} \\
\midrule
\multicolumn{2}{l}{group 1} & \multicolumn{2}{c}{0.216 (0.366)} & \multicolumn{2}{c}{2.297} & \multicolumn{2}{c}{0.094} & \multicolumn{1}{c}{0.865} & \multicolumn{1}{c}{-0.234} & \multicolumn{1}{c}{-0.164} & \multicolumn{1}{c}{-0.216} & \multicolumn{1}{c}{0.403} & \multicolumn{1}{c}{4.856} \\
\bottomrule
\end{tabular}}
\end{center}
\fontsize{10pt}{12pt}\selectfont here's something description for the table
\end{table}
\end{document}
答案1
由于这两个面板的结构似乎除了第一列中的标签之外几乎没有任何共同之处,我想不出一个好的理由来尝试将两个表格的列对齐。事实上,我会使用两个独立的tabular*
环境,每个列结构单独优化。我还会摆脱几乎所有的\multicolumn
“包装器”——它们的使用只有在标题行中才是合理的。(旁白:究竟是谁教你把每个单元格都装进\multicolumn
包装器里的——那个人有很多解释要做……)一定要简化标题行中的材料;这样就可以选择\small
字体大小了。(相反,如果你把所有这些%
符号都保留在标题单元格中,你就必须切换到\footnotesize
或甚至\scriptsize
才能让表格适合。)
\documentclass[twoside, a4paper, 12pt]{article}
\usepackage{booktabs,tabularx}
\usepackage[labelsep=newline,singlelinecheck=false]{caption}
\usepackage[english]{babel}
\usepackage[margin=1in]{geometry}
\usepackage{dcolumn}
\newcolumntype{d}[1]{D..{#1}}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}[ht!]
\small
\captionsetup{font={small,bf}}
% We use 'tabular*' to auto-determine intercolumn whitespace:
\setlength\tabcolsep{0pt}
\caption{Here's a title for the table}
\begin{tabular*}{\textwidth}{l @{\extracolsep{\fill}}d{1.3} d{1.0} *{4}{d{2.0}} d{1.3} d{2.0} *{5}{d{1.0}} }
\multicolumn{5}{l}{Panel A. Here's a title} \\
\toprule
& \multicolumn{6}{c}{Ranges (in percent)} & \multicolumn{7}{c}{Ranges (in percent)} \\
\cmidrule{2-7} \cmidrule{8-14}
& \mc{Mean} & \mc{$<$10} & \mc{10--30} & \mc{30--50} & \mc{50--70} & \mc{$>$70}
& \mc{Mean} & \mc{$<$10} & \mc{10--20} & \mc{20--30} & \mc{30--40} & \mc{40--50} & \mc{$>$50} \\
\midrule
group 1 & 0.228 & 4 & 11 & 3 & 1 & 1 & 0.056 & 16 & 3 & 1 & 0 & 0 & 0 \\
group 2 & 0.343 & 0 & 9 & 9 & 1 & 1 & 0.126 & 12 & 3 & 3 & 0 & 1 & 1 \\
group 3 & 0.495 & 0 & 0 & 15 & 4 & 1 & 0.212 & 8 & 4 & 4 & 0 & 0 & 4 \\
group 4 & 0.639 & 0 & 0 & 4 & 6 & 10 & 0.258 & 4 & 4 & 4 & 4 & 0 & 4 \\
group 5 & 0.747 & 0 & 0 & 3 & 3 & 14 & 0.260 & 2 & 6 & 5 & 4 & 0 & 3 \\
\bottomrule
\end{tabular*}
\bigskip
\begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}} *{8}{d{2.3}} *{2}{d{1.3}}}
\multicolumn{6}{l}{Panel B. Here's a slightly longer title} \\
\toprule
& \mc{$\hat{\alpha}$} & \mc{($p$-value)} & \mc{$\hat{\sigma}_{\varepsilon}$} & \mc{IR} & \mc{$\hat{\beta}^{m}$} & \mc{$\hat{\beta}^{s}$} & \mc{$\hat{\beta}^{h}$} & \mc{$\hat{\beta}^{u}$} & \mc{Mean} & \mc{Std.\ Dev.} \\
\midrule
group 1 & 0.216 & (0.366) & 2.297 & 0.094 & 0.865 & -0.234 & -0.164 & -0.216 & 0.403 & 4.856 \\
\bottomrule
\end{tabular*}
\bigskip
Here's a description for the table
\end{table}
\end{document}