135

Looking to put a table and a figure side by side so that the table and figure have their own captions. A crude sketch

 ------------              -----------------
    TABLE 
  | a |  b |                     FIGURE
  | c |  d |
 ------------             
Table 2: Caption           -----------------
                           Figure 7: Caption

The closest I've gotten is:

\begin{table}%
\centering
\parbox{0.4\textwidth}{
\begin{footnotesize}
\begin{tabular}{| l | r |} \hline
some & table\\
\end{tabular}
\end{footnotesize}
\caption{Table}
\label{tab:table}
}
\qquad
\begin{minipage}[c]{0.53\textwidth}%
\centering
    \includegraphics[width=1\textwidth]{awesome}
\caption{Figure}
\label{fig:figure}
\end{minipage}
\end{table}

But that gives two Table X: Caption captions. I didn't find anything in subfig.

Help?

badroit
  • 7,557
  • 1
    Related: http://tex.stackexchange.com/questions/101980/table-and-figure-side-by-side-with-table-caption-above-figure-caption-below – badroit Mar 11 '13 at 19:22

2 Answers2

117

Use a floatrow environment of the package of the same name.

\documentclass{article}

\usepackage{floatrow}
% Table float box with bottom caption, box width adjusted to content
\newfloatcommand{capbtabbox}{table}[][\FBwidth]

\usepackage{blindtext}

\begin{document}

\blindtext

\begin{figure}
\begin{floatrow}
\ffigbox{%
  \rule{3cm}{3cm}%
}{%
  \caption{A figure}%
}
\capbtabbox{%
  \begin{tabular}{cc} \hline
  Author & Title \\ \hline
  Knuth & The \TeX book \\
  Lamport & \LaTeX \\ \hline
  \end{tabular}
}{%
  \caption{A table}%
}
\end{floatrow}
\end{figure}

\end{document}

enter image description here

Werner
  • 603,163
lockstep
  • 250,273
  • 4
    Many thanks. Worked perfectly: floated, correct labelling, separate captions, and even handled the footnote in my table correctly! – badroit Dec 10 '10 at 18:01
  • I don't know where I had my head. I could have hit on this idea, too. (+1) – Thorsten Donig Dec 10 '10 at 18:19
  • I am getting crazy with this minifigure. I can put two figures side by side, but I cannot get two captions (one left, one right). And I copied examples from the internet! Your examples work, but how to put a figure with \includegraphics[width=0.5\textwidth]{figs2/fig5.eps} in your examples and not a black square and a table? Thanks, Alex –  Nov 13 '11 at 16:51
  • 4
    @alex: In my example, replace \rule{3cm}{3cm} with \includegraphics{<whatever>}. – lockstep Nov 13 '11 at 16:55
  • :) ...23 hours to go. – badroit Jan 09 '12 at 21:35
  • 3
    It was a joke, I swear! It was a joke! And I didn't remember I answered one of your questions! ... But this is a nice surprise. :-) – lockstep Jan 09 '12 at 21:41
  • 1
    ...are you saying my questions aren't memorable? :P Anyways, don't spend it all in one shop. – badroit Jan 11 '12 at 03:25
  • 9
    I get the error: Package floatrow Error: Do not use float package with floatrow. will floatrow replace float? or is there another workaround ? – Fry Feb 06 '14 at 21:18
  • @Fry floatrow replaces float. – lockstep Feb 06 '14 at 21:30
  • @lockstep. Where should the figure.eps be loaded in the upper code? Thank you very much. – DavidC. Jun 30 '14 at 22:16
  • @DavidC. Instead of \rule. – lockstep Jul 01 '14 at 00:40
  • 4
    The suggestion and the code example are great, however, the figure and table seem to each take half the page width. What can one do, if the figure is rather thin, but the table rather wide? Here is a screenshot: http://dl.dropbox.com/u/29095240/2014-10-06%20Selection_003.png – Peter Lustig Oct 06 '14 at 17:05
  • @PeterLustig I ended up using the second option of Thorsten's answer... a pity it doesn't float, although synchronizing two different floats numbers is a bit difficult. – Rmano Jan 31 '15 at 11:41
  • 2
    i get: Undefined control sequence. \newfloatcommand – droid192 Apr 27 '19 at 10:27
83

You can use the »caption« package. See code below for an example derived from the package manual.

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}

\DeclareCaptionLabelFormat{andtable}{#1~#2  \&  \tablename~\thetable}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \rule{6.4cm}{3.6cm}
    \qquad
    \begin{tabular}[b]{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}
    \captionlistentry[table]{A table beside a figure}
    \captionsetup{labelformat=andtable}
    \caption{A table beside a figure}
  \end{figure}
\end{document}

You will find more details in the manual. This is not exactly what you want, but it would float.


alt text


Supplement:

Another solution that would give the desired output. But this won't float.

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage[font=small,labelfont=bf]{caption}

\begin{document}
  \begin{minipage}{\textwidth}
  \begin{minipage}[b]{0.49\textwidth}
    \centering
    \rule{6.4cm}{3.6cm}
    \captionof{figure}{A table beside a figure}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.49\textwidth}
    \centering
    \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}
      \captionof{table}{A table beside a figure}
    \end{minipage}
  \end{minipage}
\end{document}

alt text

  • Thorsten, many thanks for the detailed answer and excellent examples. I went with the other answer since it's essentially a floating version of your second example where I can have separate captions. – badroit Dec 10 '10 at 18:03
  • 3
    why does this no longer work if you try to put the captions above the figure and table? – emily Jul 08 '12 at 16:35
  • 1
    @emily a fix for that can be found here: https://tex.stackexchange.com/questions/459423/table-next-to-figure-with-table-caption-on-top-but-figure-caption-on-bottom – Thomas Wagenaar Nov 26 '20 at 12:51
  • 3
    with the minipage version, when table title is at the top, and the figure is taller, can you set the table verticle_alignment=centre? or align at top. – Anthony Aug 06 '21 at 22:54