# 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. –  Axel Sommerfeldt 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.

-
Wow, that table looks really nice! IMHO shows that thoughtful vertical white space can go a long way eliminating the need for any (h)rules. –  morbusg Aug 23 '11 at 16:43

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

\documentclass{article}
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{booktabs}% http://ctan.org/pkg/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{array}% http://ctan.org/pkg/array
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\begin{table}[ht]
\centering
\caption{An interesting table}
\label{tbl:interesting}

\medskip

\begin{tabularx}{\linewidth}{*{3}{p{.33\linewidth}}}
\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}{*{2}{p{.49\linewidth}}}
\multicolumn{2}{c}{Panel B: Other stuff} \\ \toprule
School & State \\ \midrule
Harvard & MA \\
Yale & CT \\
Brown & RI \\ \bottomrule
\end{tabularx}
\end{table}
\end{document}


-

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}

-