1

I would like to put "U.S. census" in the middle of the given space, and also "GroupA" as well. Currently it's somewhat shifted. How should I combine the rows?

\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} 

Current image

I tried multirow and makecell functions but both didn't work. Thanks in advance.

3
  • 2
    Welcome to TeX.SE. Please clarify what you mean by "middle of the given space". Commented Dec 28, 2023 at 23:14
  • Oh sorry for that. The word "U.S. Census" is skewed upward, but I want to put that in the same line as "Group B" so that it could be in the middle of three rows. Please check out the Current image file. Commented Dec 28, 2023 at 23:31
  • 1
    Than you should move "U.S. Census" from the first row to the second. Why you have empty first column? More background of your table will be helpful. Commented Dec 28, 2023 at 23:55

2 Answers 2

2

Is one of the following two solutions (close to) what you're after?

enter image description here

\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} 
5
  • Thank you so much!!! Would it be possible to shift "Group A" in the middle of second and third rows? Commented Dec 29, 2023 at 1:03
  • Oh, I meant moving "GroupA" slightly downward so that it sets in the middle of the line between "GroupB" and "A, B, C, D" since the column with GroupA has a remaining space. Commented Dec 29, 2023 at 2:12
  • @snowman - Please see my updated answer. Commented Dec 29, 2023 at 2:14
  • Thank you so much! I meant exactly mixing those two solutions that you provided. Group A is too upward in the first solution and too downward in the second solution - Would it be possible to put it exactly in the middle? Commented Dec 29, 2023 at 2:39
  • @snowman - Absolutely. Be sure to load the multirow package in the preamble. Then, take the first solution, replace Group A with \multirow{2.3}{*}{Group A}, and delete \cmidrule(lr){3-3}. Commented Dec 29, 2023 at 3:09
1

With 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} 

enter image description here

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.