7

The question is similar to this one: How to display a content in two-column layout in LaTeX? but about placing two tables side by side.

I have two small tables looking like that:

\begin{table}[t]
\begin{tabular}{|c|l||r|r||r|r|}
%content goes here
\end{tabular}
\caption{some caption} 
\end{table}

\begin{table}[t]
\begin{tabular}{|c|l||r|r||r|r|}
%content goes here
\end{tabular}
\caption{some caption for second table} 
\end{table}

I have one-column document and these tables are really narrow, so I would like to display them side by side (with separate captions) insted of one under another with a lot of unused, white space.

I tried to do it with this \multicols but it seems that floats (tables here) cannot be placed inside of it.

Any ideas?

EDIT
OK, I've done something like that:

\begin{table}[h]
\begin{minipage}[b]{80mm}
\begin{tabular}{|c|l||r|r||r|r|}
%//first table goes here
\end{tabular}
    \caption{some caption for first table} 
\end{minipage}

\begin{minipage}[b]{80mm}
\begin{tabular}{|c|l||r|r||r|r|}
%//second table goes here
\end{tabular}
    \caption{some caption for second table} 
\end{minipage}

 \end{table}

But the table is always using as much space, as it needs, no matter what size of minipage I would set. For example, if I have 80 mm for minipage, the caption will be limited to these 80 mm but the table will be wider.

If I have two tables, and one table is just a little bit too wide, it would not apper next to first table, but underneath.

Is there any way to limit the table to specified width? Or to force them to appear one next to another? Or maybe how to change the font size just for one of the tables?

Community
  • 1
  • 1
Gacek
  • 10,184
  • 9
  • 54
  • 87

3 Answers3

20

The reason your second table is going below the first table instead of right next to it is because of the space between the two minipages. You have to have the statements right below the other, otherwise latex would treat it like an end line. Took me about a week to figure this out for my own tables.

\end{minipage}
\begin{minipage}[b]{80mm}

Instead of:

\end{minipage}

\begin{minipage}[b]{80mm}
Derek
  • 201
  • 2
  • 2
6

Use two minipages or two tabular environments in the same table environment (but then you'll have to do something about the captions if you need them).

lhf
  • 70,581
  • 9
  • 108
  • 149
3

Use the subfig package like this:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[bf,small,tableposition=top]{caption}
\usepackage{subfig}
\begin{document}

\begin{table}
\centering
\subfloat[First table.]{%
\begin{tabular}{|c|l||r|r||r|r|}
a & b & c & d & e & f \\
a & b & c & d & e & f \\
\end{tabular}}%
\qquad\qquad% --- set horizontal distance between tables here
\subfloat[Second table.]{%
\begin{tabular}{|c|l||r|r||r|r|}
a & b & c & d & e & f \\
a & b & c & d & e & f \\
a & b & c & d & e & f \\
a & b & c & d & e & f \\
\end{tabular}}
\end{table}

\end{document}

This will take care of vertical alignment of the tables when they have a different number of rows like in this example. Notice also that tables have their captions above them, while figures have their caption below them. The excellent caption package can help you change that if you want.

Finally, you should take a look at the booktabs package for professional quality typesetting of tables. It asks you to avoid vertical lines and instead use horizontal lines. The result is normally much better, IMHO.

Martin Geisler
  • 72,968
  • 25
  • 171
  • 229
  • Nice, but there is one problem - I need to use custom style (from IEEE) and when I use subfloats, it destroys this custom style and uses default ones for tables. – Gacek Jun 20 '10 at 14:17
  • Is there a way to get captions to go on top of tables instead of under them? – mpenkov Feb 26 '14 at 10:24