我想将“美国人口普查”和“GroupA”放在给定空间的中间。目前它有些偏移。我应该如何合并行?
\begin{table}
\begin{tabular}{lrrrrrr}
\toprule
& U.S. Census & \multicolumn{5}{c}{Study2} \\
& & GroupA & \multicolumn{4}{c}{GroupB} \\
& & & A & B & C & D \\
\bottomrule
\end{tabular}
\end{table}
我尝试了 multirow 和 makecell 函数,但都没有用。提前致谢。
答案1
以下两种解决方案之一是否(接近)是您所追求的?
\documentclass{article}
\usepackage{booktabs,caption}
\begin{document}
\begin{table}
\centering
\caption*{First possibility}
\begin{tabular}{@{} l c r rrrr @{}}
\toprule
&& \multicolumn{5}{c@{}}{Study2} \\
\cmidrule(l){3-7}
XYZ & U.S. Census & Group A & \multicolumn{4}{c@{}}{Group B} \\
\cmidrule(lr){3-3} \cmidrule(l){4-7}
&& & A & B & C & D \\
\midrule
% more table stuff
\\
\bottomrule
\end{tabular}
\vspace{0.5in}
\caption*{Second possibility}
\begin{tabular}{@{} l c r rrrr @{}}
\toprule
&& \multicolumn{5}{c@{}}{Study2} \\
\cmidrule(l){3-7}
XYZ & U.S. Census & & \multicolumn{4}{c@{}}{Group B} \\
\cmidrule(l){4-7}
&& Group A & A & B & C & D \\
\midrule
% more table stuff
\\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
和tabularray
:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\begin{document}
\begin{table}\centering
\begin{tblr}{colspec={lrrrrrr}}
\toprule
&\SetCell[r=3]{c} U.S. Census & \SetCell[c=5]{c} Study2 &&&& \\
&& \SetCell[r=2]{c} GroupA & \SetCell[c=4]{c} GroupB &&&\\
& & & A & B & C & D \\
\bottomrule
\end{tblr}
\end{table}
\begin{table}\centering
\begin{tblr}{colspec={lrrrrrr}}
\toprule
&\SetCell[r=3]{c} U.S. Census & \SetCell[c=5]{c} Study2 &&&& \\
\cmidrule{3-7}
&& \SetCell[r=2]{c} GroupA & \SetCell[c=4]{c} GroupB &&&\\
\cmidrule{4-7}
& & & A & B & C & D \\
\bottomrule
\end{tblr}
\end{table}
\end{document}