5

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:

enter image description here

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
            Table head & Table head \\ \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?

5
  • possible duplicate of Table and Figure side-by-side with independent captions Sep 16, 2011 at 13:26
  • 1
    You should add the code you use, because the result is not the same with the default settings.
    – egreg
    Sep 16, 2011 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. Sep 16, 2011 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. Sep 16, 2011 at 13:34
  • Yes, you're right. Sep 16, 2011 at 13:42

3 Answers 3

4

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.

2
  • 1
    Thanks, this instantly resolved it! I opened up the MiKTeX Package Manager and updated a few packages, and it's working perfectly now. Sep 16, 2011 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. Sep 16, 2011 at 15:54
3

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
            Table head & Table head \\ \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}
0

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
            Table head & Table head \\ \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
            Table head & Table head \\ \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
10
  • 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? Sep 16, 2011 at 13:42
  • Would another approach be useful for you? I mean, using the subcaption package instead of subfig? Sep 16, 2011 at 13:44
  • 1
    That was really not obvious! An MWE should be included at all times...
    – Count Zero
    Sep 16, 2011 at 13:44
  • Nop. With the code you just posted I still can't reproduce the problem (after uncommenting the hyperref line). Sep 16, 2011 at 13:48
  • 1
    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, 2011 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.