# How can I have two tables side by side?

Suppose I have two tables that don't have many columns (3, for example). How can I position them side by side?

-
 This question is quite popular, but the answers seem to have quite some overlap, but lack a coherent comparsion of the pros & cons of the different techniques used: minipage, subfig & subfloat, \quad (?), parbox, subcaption & subtable. Is there a consensus of what's considered best, if both "subtables" also have some basic (not a fully-fledged one with the "Table 2.1"-bit) caption? – nutty about natty Apr 18 at 5:59

I don't know that this is the best way, but you could make a 2-column table with a single row. In each cell of the table, wrap one of your intended tables in a minipage environment. Thus:

\documentclass{article}

\begin{document}

\begin{tabular}{cc}
\begin{minipage}{.5\linewidth}
\begin{tabular}{ll}
1 & 2
\end{tabular}
\end{minipage} &

\begin{minipage}{.5\linewidth}
\begin{tabular}{ll}
3 & 4
\end{tabular}
\end{minipage}
\end{tabular}

\end{document}

-
I'd appreciate a comment with the down vote; I might then learn something about what makes this a bad solution. – vanden Sep 7 '10 at 4:23
Sticking it in a minipage makes no sense to me at all. – TH. Sep 7 '10 at 5:01
Does this not work? My first guess was to solve it in this way... so how come it got a downvote? – Johan Sep 7 '10 at 5:03
I don't know why it got a downvote, but for my eyes the code has some faults: It gives an overful hbox message as the \parindent is not taken into account. It doesn't do what it probably wants to do: the tabular are not centered in the line as they are left aligned in the minipages. Also a minipage + an external tabular looks like an overkill (one at least could certainly be dropped) and makes the code difficult to read and changed. – Ulrike Fischer Sep 7 '10 at 10:19
@Ulrike: Thanks; that's very helpful. – vanden Sep 7 '10 at 17:03

Ceteris paribus, you might consider the subfig package. It is suitable for subtables and subfigures and combinations of these. For myself, I've managed much mileage from it.

-
I'm looking at the documentation and I can only find examples using figures. Could you post an example with tables? – bada Sep 7 '10 at 4:30
@bada. Sorry man, you simply can't come back 8 mins after a solution has been posted without at least showing a little effort first. Seriously, have you tried reading the documentation in some detail (not just 5 minute's worth) then tried loading the subfig package, inserted a few tables and otherwise played around a little with it? – Geoffrey Jones Sep 7 '10 at 4:54
I got it working, I just had to use the \begin{table} instead of the \begin{figure} scope with the \subfloat command, which is idiotic to begin with since as far as I can tell that wasn't mentioned anywhere, but whatever. And you - along with people that agree with this line of thinking of yours - are the reason they call people "Linux snobs" dude. – bada Sep 7 '10 at 5:21
Excellent! Very well done! – Geoffrey Jones Sep 7 '10 at 6:43
@bada you are right, using \begin{table} is totally unreasonable, I mean since putting one tabular environment in a table float is very far fetched as well - NOT! – maxschlepzig Sep 7 '10 at 7:35
show 1 more comment

Just put two tabular environments side by side. Add spacing as desired.

\begin{tabular}{ccc}
\hline
a&b&c\\
\hline
\end{tabular}
\begin{tabular}{ccc}
\hline
d&e&f\\
\hline
\end{tabular}


If you want to use subfig because you want them to have separate captions, then that is simple as well.

\subfloat[caption]{\begin{tabular}{...}...\end{tabular}}
\subfloat[caption]{\begin{tabular}{...}...\end{tabular}}


If you want two tables that are independent, and thus don't want to use \subfloat, you can use \parbox.

\begin{table}
\parbox{.45\linewidth}{
\centering
\begin{tabular}{ccc}
\hline
a&b&c\\
\hline
\end{tabular}
\caption{Foo}
}
\hfill
\parbox{.45\linewidth}{
\centering
\begin{tabular}{ccc}
\hline
d&e&f\\
\hline
\end{tabular}
\caption{Bar}
}
\end{table}


This is basically the same as before just that I've centered each tabular in a \parbox with an included caption and wrapped the whole thing in a table.

-

If you want two tabulars next to each other in a (floating) table environment, then you can use minipages

\begin{table}[!htb]
\caption{Global caption}
\begin{minipage}{.5\linewidth}
\caption{}
\centering
\begin{tabular}{ll}
1 & 2
\end{tabular}
\end{minipage}%
\begin{minipage}{.5\linewidth}
\centering
\caption{}
\begin{tabular}{ll}
3 & 4
\end{tabular}
\end{minipage}
\end{table}


Loading the caption package will allow easy customization, and will remove the : when the caption is empty.

If you'd like 'sub'tables, then you can use the subcaption package which introduces the subtable environment (and a lot more); the subtable environment takes the same mandatory and optional arguments as the minipage

\documentclass{article}
\usepackage{subcaption}
\begin{document}

\begin{table}[!htb]
\caption{Global caption}
\begin{subtable}{.5\linewidth}
\centering
\caption{}
\begin{tabular}{ll}
1 & 2
\end{tabular}
\end{subtable}%
\begin{subtable}{.5\linewidth}
\centering
\caption{}
\begin{tabular}{ll}
3 & 4
\end{tabular}
\end{subtable}
\end{table}

\end{document}


Note that in both cases I've used a % at the end of the environment to stop overfull hboxes from the additional space added by the minipage.

-
Why would I want subtables vs tabulars? Of the two methods you describe in your answer, which is better (and why) ? – nutty about natty Apr 18 at 6:51
On a second glance: is the main (visible) difference between the two methods the way the "sub"-captions look (e.g., "Table 2" vs. "(a)") ? – nutty about natty Apr 18 at 6:57
@nuttyaboutnatty yes, your second comment is accurate. It depends how you want the captions (and references) to look. It's up to you which you think is better :) – cmhughes Apr 18 at 17:00