# Create a table with two parts with different tabular features

I'm trying to build a table that has two panels with different numbers of columns. For example:

Table 1: An interesting table

Panel A: Some stuff
First name      Last name       Product
Bubba           Gump            Shrimp
Steve           Jobs            Happiness

Panel B: Other stuff
School       State
Harvard      MA
Yale         CT
Brown        RI


I would like the 3 columns of Panel A and the 2 columns of Panel B to fill the horizontal space of the table.

I imagined using two different \tabular commands within a \table would work, but it doesn't. I also found the subfigure package, but I think that only lets you stack tables horizontally, not vertically.

Any ideas? Thanks!

• The subfigure package lets you stack tables vertically, for example by placing a \\ or \par between the \subfigures. – user2574 Aug 23 '11 at 16:15
• I wouldn't spread the columns across the entire \textwidth, that looks terrible. Just compare the output of Stefan's solution (not spread) with Werner's's (spread). Using the booktabs package is a good idea though. – doncherry Aug 23 '11 at 17:35

Within a table environment, you can use different tabular environments, of different types and with a different number of columns. Here's an example with sub captions:

\documentclass{article}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabularx}
\begin{document}
\begin{table}
\centering
\caption{An interesting table}
\subcaption*{Panel A: Some stuff}
\begin{tabular}{lcr}
First name & Last name  & Product \\
Bubba & Gump & Shrimp \\
Steve & Jobs & Happiness
\end{tabular}
\bigskip
\subcaption*{Panel B: Other stuff}
\begin{tabular}{ll}
School & State \\
Harvard & MA \\
Yale & CT \\
Brown & RI
\end{tabular}
\end{table}
\end{document}


Here I used the subcaption packages. A good alternative is the subfig package. However, the subfigure package is obsolete.

With liberal use of the \multicolumn{.}{.}{...} command, you can get away with spreading the table across the entire \linewidth:

\documentclass{article}

\usepackage{array,booktabs}

\begin{document}

\begin{table}[ht]
\centering
\caption{An interesting table}
\label{tbl:interesting}

\begin{tabular}{*{6}{p{.16\linewidth}}}
\multicolumn{6}{c}{Panel A: Some stuff} \\
\toprule
\multicolumn{2}{p{.33\linewidth}}{First name} & \multicolumn{2}{p{.33\linewidth}}{Last name} &
\multicolumn{2}{p{.33\linewidth}}{Product} \\
\midrule
\multicolumn{2}{l}{Bubba} & \multicolumn{2}{l}{Gump} & \multicolumn{2}{l}{Shrimp} \\
\multicolumn{2}{l}{Steve} & \multicolumn{2}{l}{Jobs} & \multicolumn{2}{l}{Happiness} \\
\bottomrule
\\
\multicolumn{6}{c}{Panel B: Other stuff} \\
\toprule
\multicolumn{3}{p{.49\linewidth}}{School} & \multicolumn{3}{p{.49\linewidth}}{State} \\
\midrule
\multicolumn{3}{l}{Harvard} & \multicolumn{3}{l}{MA} \\
\multicolumn{3}{l}{Yale} & \multicolumn{3}{l}{CT} \\
\multicolumn{3}{l}{Brown} & \multicolumn{3}{l}{RI} \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


Since the two panels are contained in the same tabular, they span the same width. The above uses the booktabs package for presentation of the tabular environments. However, it is not necessarily needed. If you want to drop it, you should also drop/replace the \toprule, \midrule and \bottomrule rules with \hline or another preference.

Alternatively, you could also use the tabularx package to spread columns across a specific width:

\documentclass{article}

\usepackage{booktabs,tabularx}

\begin{document}
\begin{table}[ht]
\centering
\caption{An interesting table}
\label{tbl:interesting}

\medskip

\begin{tabularx}{\linewidth}{ X X X }
\multicolumn{3}{c}{Panel A: Some stuff} \\
\toprule
First name & Last name & Product \\
\midrule
Bubba & Gump & Shrimp \\
Steve & Jobs & Happiness \\
\bottomrule
\end{tabularx}

\bigskip

\begin{tabularx}{\linewidth}{ X X }
\multicolumn{2}{c}{Panel B: Other stuff} \\
\toprule
School & State \\
\midrule
Harvard & MA \\
Yale & CT \\
Brown & RI \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}


• how did you get that value: \begin{tabular}{*{6}{p{.16\linewidth}}} ? 1/6 = 0.166, so it cannot be that. – ghx Sep 17 '19 at 22:40
• @ghx: I wanted to set the tabular within the \linewidth, and for 6 columns to fit, I used 1/6 of \linewidth for each, or 0.16\linewidth. – Werner Sep 17 '19 at 22:55
• thanks I understand that, but isn't 1/6 = 0.1667 (rounded)? So I wonder how this ends up precise. – ghx Sep 17 '19 at 23:05
• @ghx: Yes, 1/6 ~ 0.1667, but in *{6}{p{.16\linewidth}} there are 6 columns and 12 \tabcolseps that also need to be considered: One on either side of the tabular's outer columns, and 2 \tabcolseps between each column pair (there are 5 of those). I rounded 1/6 down to 0.16 to allow for these to also fit within the \linewidth. Similarly for .33\linewidth when dealing with 3 columns and .49\linewidth for 2 columns. – Werner Sep 17 '19 at 23:16

You can use the multicol column package to have data span multiple columns.

\documentclass{article}
\usepackage{multicol}

\begin{document}
\begin{tabular}{lll}
\multicolumn{3}{c}{Panel A: Some stuff}\\
First name      &Last name       &Product\\
Bubba           &Gump            &Shrimp\\
Steve           &Jobs            &Happiness\\
\\
\multicolumn{3}{c}{Panel B: Other stuff}\\
School       &State\\
Harvard      &MA\\
Yale         &CT\\
Brown        &RI\\
\end{tabular}
\end{document}

• Thanks, but I think I need a different approach. I want the 2 columns in panel B to span just as much space as the 3 columns in panel A. This table has a 3rd (blank) column in panel B, which I am trying not to have. – itzy Aug 23 '11 at 16:16
• You can use the \multicolumn macro to adjust that. For example you can use \multicolumn{2}{c}{State} to have that column span the two columns. If I am still not understanding please provide a more detailed example. – Peter Grill Aug 23 '11 at 16:18

maybe like this?

\begin{tabular}{lll}
\hline
\multicolumn{ 3}{c}{Panel A: Some stuff} \\
\hline
First name &  Last name &    Product \\
\hline
Bubba &       Gump &     Shrimp \\
\hline
Steve &       Jobs &   Happines \\
\hline
\multicolumn{ 3}{c}{Panel B: Other stuff} \\
\hline
School & \multicolumn{ 2}{l}{State} \\
\hline
Harvard & \multicolumn{ 2}{l}{CT} \\
\hline
Yale & \multicolumn{ 2}{l}{CI} \\
\hline
Brown & \multicolumn{ 2}{l}{RI} \\
\hline
\end{tabular}