# Figure and table side-by-side in subfloats

A very similar question has been asked before:

Table and Figure side-by-side with independent captions

I'm trying to accomplish this, but while using the subfig package. The image below depicts almost what I want, but as you can see, the table is not aligned correctly:

The TeX I'm working with is:

\begin{figure}[h]
\caption{A figure and a table, side-by-side}
\centering
\subfloat[A figure left of a table]{
\rule{6.4cm}{3.6cm}
}
\subfloat[A table right of a figure]{
\begin{tabular}{cc}\hline
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\ \hline
\end{tabular}
}
\end{figure}


I've tried throwing a few minipages into the mix, but to no avail. How can I align the top of the table to the top of the figure?

-
possible duplicate of Table and Figure side-by-side with independent captions –  Gonzalo Medina Sep 16 '11 at 13:26
You should add the code you use, because the result is not the same with the default settings. –  egreg Sep 16 '11 at 13:26
@egreg You're right; I tried a clean document and they align just fine. I'll try to figure out what's causing the problem and post it as the answer. –  Paul Lammertsma Sep 16 '11 at 13:32
Gonzalo, the difference here is that I'm trying to use subfloats. References to the figure and the table would appear as 3.1(a) and 3.2(b). The other question I cited specifically calls for independent captions. –  Paul Lammertsma Sep 16 '11 at 13:34
Yes, you're right. –  Gonzalo Medina Sep 16 '11 at 13:42

The caption package version you use is too old to work fine with the actual version of hyperref.

That's explaining both issues, the wired behaviour when used with the subfig package, and the error you get when using the subcaption package. So updating the caption package (or even better: your whole TeX system) should help.

(Current versions of the hyperref package need at least caption v3.1m from 2010/01/09)

Addendum: The very next version 1.1b of the subcaption package will typeout a more reasonable error message.

-
Thanks, this instantly resolved it! I opened up the MiKTeX Package Manager and updated a few packages, and it's working perfectly now. –  Paul Lammertsma Sep 16 '11 at 15:46
I've noticed I do have to shuffle the imports around, as cmhughes mentioned. Some orderings reproduce the original problem, but I'm delighted that this problem is resolved. –  Paul Lammertsma Sep 16 '11 at 15:54

I had the exact same problem, the following worked for me:

\usepackage{subfigure}

\begin{figure}[h]
\caption{A figure and a table, side-by-side}
\centering
\subfloat[A figure left of a table]{
\raisebox{-.5\height}{\rule{6.4cm}{3.6cm}}
}
\subfloat[A table right of a figure]{
\begin{tabular}{cc}\hline
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\ \hline
\end{tabular}
}
\end{figure}

-

My specific problem appears to be caused by the hyperref package. Removing \usepackage{hyperref} resolved the layout problem, although I don't know exactly what was causing it.

With subfig, I get the following warning:

\caption will not be redefined since it's already on input line 15

\documentclass[a4paper]{article}

\usepackage{graphicx}
\usepackage{subfig}

%% Enabling this package appears to cause the problem
% \usepackage{hyperref}

\begin{document}

\begin{figure}[h]
\caption{A figure and a table, side-by-side}
\centering
\subfloat[A figure left of a table]{
\rule{6.4cm}{3.6cm}  %% <- line 15
}
\subfloat[A table right of a figure]{
\begin{tabular}{cc}\hline
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\ \hline
\end{tabular}
}
\end{figure}

\end{document}


With subcaption, I get the following compilation error:

Package caption Error: Something's wrong--perhaps a missing \caption on input line 30 in "test2.tex"

\documentclass[a4paper]{article}

\usepackage{graphicx,caption,subcaption}

%% Enabling this causes problems
%\usepackage{hyperref}

\begin{document}

\begin{figure}
\centering
\subcaptionbox{}{
\rule{6.4cm}{3.6cm}
}
\hfill
\subcaptionbox{}{
\begin{tabular}{cc}\hline
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\
Some values & Some values \\ \hline
\end{tabular}
}
\caption{Test images}
\end{figure}

\end{document}  %% <- line 30

-
Hmmm... adding hyperref to your code snippet (and loading subfig) doesn't allow me to reproduce the strange behaviour mentioned, so there must be something else going on. Can you complete your code to a proper minimal working example illustrating the problem? –  Gonzalo Medina Sep 16 '11 at 13:42
Would another approach be useful for you? I mean, using the subcaption package instead of subfig? –  Gonzalo Medina Sep 16 '11 at 13:44
That was really not obvious! An MWE should be included at all times... –  Count Zero Sep 16 '11 at 13:44
Nop. With the code you just posted I still can't reproduce the problem (after uncommenting the hyperref line). –  Gonzalo Medina Sep 16 '11 at 13:48
I haven't been able to reproduce the unwanted output. I assume the actual document is a lot more complicated- be careful to load the hyperref package last- see this post: tex.stackexchange.com/questions/1863/… –  cmhughes Sep 16 '11 at 15:05