7

Using 'subfigure', how can I create subtables within a table, such that a) subcaptions are underneath each subtable, and b) there's a reasonable horizontal gap between the subtables? So far I've only be able to get the subcaptions on top, and no reasonable gap, e.g. with following code:

\documentclass{article}
\usepackage{subfigure}
\begin{document}
\begin{table}
\centering
\subtable[caption1]
{\begin{tabular}{c c c}
\ $a$ & $b$ & $c$ \\
\hline 0 & 0 & 0 \\
\ 1 & 1 & 1 \\
\end{tabular}}
\subtable[caption2]
{\begin{tabular}{c c c}
\ $a$ & $b$ & $c$ \\
\hline 0 & 0 & 0 \\
\ 1 & 1 & 1 \\
\end{tabular}}
\caption{caption for whole table}
\end{table}
\end{document}
David Carlisle
  • 757,742
  • One thing that doesn't work is '\usepackage[FIGBOTCAP]{subfigure}'. But having subcaptions underneath should be the default, according to the 'subfigure' manual. – Harry Macpherson Jan 08 '12 at 19:32
  • Perhaps I'm missing something, but I'd remove the explicit \ (space) commands because the first column doesn't align properly (see also Percusse's output). Alternatively, add an explicit space after the \hline command. –  Jan 08 '12 at 21:18

1 Answers1

16

Instead of the subfigure package which is now obsolete and should be replaced with subfig package, you can use subcaption package with almost identical code. I am modifying the example in the manual:

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

\begin{table} \begin{subtable}{.5\linewidth}\centering {\begin{tabular}{ccc} \ $a$ & $b$ & $c$ \ \hline 0 & 0 & 0 \ \ 1 & 1 & 1 \ \end{tabular}} \caption{A subtable}\label{tab:1a} \end{subtable}% \begin{subtable}{.5\linewidth}\centering {\begin{tabular}{c c c} \ $a$ & $b$ & $c$ \ \hline 0 & 0 & 0 \ \ 1 & 1 & 1 \ \end{tabular}} \caption{Another subtable}\label{tab:1b} \end{subtable} \caption{A table}\label{tab:1} \end{table} \end{document}

enter image description here

Nevermind the figure word. I just missed that.

percusse
  • 157,807
  • Many thanks for this. It does the job beautifully; the only problem is that 'subcaption' is incompatible with 'subfigure' and messes up all the other things I've done with 'subfigure' :-( Any idea how to do the job using 'subfigure'? – Harry Macpherson Jan 08 '12 at 19:38
  • 2
    @HarryMacpherson: subfigure is really obsolete. – Marco Daniel Jan 08 '12 at 19:57
  • To be honest, I don't think that you should be using subfigure anyway. See subcaption vs. subfigfor a flavor of these reasons. At least you should use subfig in my opinion... – percusse Jan 08 '12 at 19:57
  • OK thanks everyone. I've reached the conclusion, looking at what people say about subfigure, subfig, and subcaption, that I should ditch subfigure, load subcaption, RTFM for subcaption and work from there! Thanks for solving the problem I asked about, though! :) – Harry Macpherson Jan 08 '12 at 20:15
  • I have a trouble with this solution and I have posted it here: http://tex.stackexchange.com/questions/59414/issue-with-arranging-subtables – Bravo Jun 11 '12 at 08:36