7

I need to align 1 table to the right and two to the left, the layout I want to achieve is something like this:

Table layout

\begin{figure}
 \centering
  \subfloat[]{% 
  \begin{tabular}[b]{cc}
  \hline
  0 & 1\\
  \hline
  2 & 1\\
  3 & 1\\
  4 & 2\\
  5 & 3\\
  4 & 8\\
  \hline
  \end{tabular}%
  }  \qquad
  \subfloat[]{%
  \begin{tabular}[b]{ccc} 
    \hline
    1 & 2 & 3\\ 
    3 & 7 & 4\\
    4 & 5 & 4\\
    \hline
    \end{tabular}%
  \begin{tabular}[b]{ccc} 
    \hline
    1 & 2 & 3\\ 
    3 & 7 & 4\\
    4 & 5 & 4\\
    \hline
    \end{tabular}%
  }~
\end{figure}

Ted.

David Carlisle
  • 757,742
Flethuseo
  • 553

2 Answers2

8

A solution for both variants, two and three subfloats enter image description here

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

\begin{table}
\minipage[b]{0.49\linewidth}
 \centering
 \subfloat[]{%
 \begin{tabular}[b]{cc}\hline
        0 & 1\\\hline
        2 & 1\\
        3 & 1\\
        4 & 2\\
        5 & 3\\
        4 & 8\\\hline
 \end{tabular}}%
 \quad
 \subfloat[]{%
 \begin{tabular}[b]{@{}c@{}}%
    \begin{tabular}{ccc} \hline
       1 & 2 & 3\\ 
       3 & 7 & 4\\
       4 & 5 & 4\\\hline
    \end{tabular}\\[5ex]
    \begin{tabular}[b]{ccc} \hline
       1 & 2 & 3\\ 
       3 & 7 & 4\\
       4 & 5 & 4
    \end{tabular}\\\hline
  \end{tabular}}%
\caption{the one for all}

\endminipage\hfill
\minipage[b]{0.49\linewidth}
 \centering
 \subfloat[]{%
 \begin{tabular}[b]{cc}\hline
        0 & 1\\\hline
        2 & 1\\
        3 & 1\\
        4 & 2\\
        5 & 3\\
        4 & 8\\\hline
 \end{tabular}}%
 \quad
 \begin{tabular}[b]{c}%
 \subfloat[]{%
    \begin{tabular}{ccc} \hline
       1 & 2 & 3\\ 
       3 & 7 & 4\\
       4 & 5 & 4\\\hline
    \end{tabular}}\\[5ex]
 \subfloat[]{%
    \begin{tabular}[b]{ccc} \hline
       1 & 2 & 3\\ 
       3 & 7 & 4\\
       4 & 5 & 4\\\hline
    \end{tabular}}%
  \end{tabular}%

\caption{the one for all}
\endminipage
\end{table}

\end{document}
Moriambar
  • 11,466
  • This works fine on its own, but when the \subfloat captions are added the right one is further down than the left caption. Added the parent tabular on the left fixes that. – Martin Scharrer Feb 01 '11 at 11:53
  • @Martin: no, then you did something wrong ... –  Feb 01 '11 at 11:59
  • To clarify: the tables are still aligned correctly, but not the sublabels created by \subfloat. The reason seems to be the extra space caused by the bottom \hline s. After removing them in the both left and bottom right tabular the sublabels are also correctly aligned. – Martin Scharrer Feb 01 '11 at 12:11
  • Martin: Where are the sublabels (a) and (c) not aligned? –  Feb 01 '11 at 12:16
  • In the OP, the two right tabulars share one sublabel, the \subfloat is outside both tabulars. I was assuming that is what the OP wants. The resulting (a) and (b) are not aligned in this case. – Martin Scharrer Feb 01 '11 at 12:19
  • @Martin: that will also no problem for me. As I said, no need for the double tabulars. I'll edit my example –  Feb 01 '11 at 12:31
  • @Herbert: you are of course right, there shall be a (better) solution without double tabulars, but it can be fixed with some. – Martin Scharrer Feb 01 '11 at 12:36
  • Ah, putting the last \\\hline into the outer tabular. Very nice idea, I wouldn't had thought of it. BTW, I just ordered your table book last week over Dante. It's still on its way to Ireland. – Martin Scharrer Feb 01 '11 at 13:24
3

Use tabulars inside tabulars:

\documentclass{article}

\usepackage{subfig}

\begin{document}

\begin{table}
 \centering
  \subfloat[]{% 
    \begin{tabular}[b]{c}
    \begin{tabular}[b]{cc}
        \hline
        0 & 1\\
        \hline
        2 & 1\\
        3 & 1\\
        4 & 2\\
        5 & 3\\
        4 & 8\\
        \hline
    \end{tabular}%
    \end{tabular}%
  }
  \quad
  \subfloat[]{% 
    \begin{tabular}[b]{c}%
        \begin{tabular}{ccc} 
            \hline
            1 & 2 & 3\\ 
            3 & 7 & 4\\
            4 & 5 & 4\\
            \hline
            \end{tabular}
        \\\\%
        \begin{tabular}[b]{ccc} 
            \hline
            1 & 2 & 3\\ 
            3 & 7 & 4\\
            4 & 5 & 4\\
            \hline
        \end{tabular}%
        \\
    \end{tabular}%
  }%
\end{table}
\end{document}

Note, that the both parent and bottom tabular have a [b] argument. The left tabular must also be placed inside a parent tabular to get the same spacing to the subfloat label.

/edit: removed { } for inner tabulars.

Results:

Without left parent tabular:

no parent tabular

With left parent tabular:

parent tabular

The added margins can be removed by replacing {c} with {@{}c@{}} in the parent tabulars.

David Carlisle
  • 757,742
Martin Scharrer
  • 262,582
  • @Martin Scharrer The solution is good, but I would recommend you change the \figure to table so any captions can refer to tables. – yannisl Feb 01 '11 at 02:51
  • @Yiannis: Done, the OP used figure, so I first did not changed set. – Martin Scharrer Feb 01 '11 at 08:16
  • @Martin: The left outer tabular is not needed and also not the {..} for the sub tabulars –  Feb 01 '11 at 12:10
  • @Herbert: You are definitive right about the {..}, I confused that with tabularx, where they are needed. – Martin Scharrer Feb 01 '11 at 12:20
  • @Martin: no, tabularx also didn't braces around the body –  Feb 01 '11 at 12:26
  • @Herbert: They are required for tabularx inside another tabularx. Its manual says in section 3: "tabular and tabular* environments may be nested with no restriction, however if one tabularx environment occurs inside another, then the inner one must be enclosed by { }." – Martin Scharrer Feb 01 '11 at 12:30
  • @Martin: that is already a difficult case and will not always work –  Feb 01 '11 at 12:39