在背面組合列和列

在背面組合列和列

我想將“美國人口普查”放在給定空間的中間,還有“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}

在此輸入影像描述

相關內容