2

I am struggling to align figure next to table. The code is taken from here and it is:

\begin{minipage}{\textwidth}
  \begin{minipage}[b]{0.49\textwidth}
    \centering
    \includegraphics[width=0.6\linewidth]{figures/strategy_I_no_filter_ROC}
    \captionof{figure}{A figure beside a figure}
  \end{minipage}
  \hfill
  \begin{minipage}[b]{0.49\textwidth}
    \centering
    \begin{tabular}{|c|c|c|}\hline
        Strategy        &  I     &  II   \\\hline
        precision$_0$   & 0.769  &  0.783\\
        precision$_1$   & 0.806  &  0.793\\
        recall$_0$      & 0.804  &  0.796\\  
        recall$_1$      & 0.769  &  0.774\\
        f$_1^{macro}$   & 0.788  &  0.786\\
        AUC             & 0.849  &  0.855\\\hline                 
    \end{tabular}
      \captionof{table}{Classification results of normal intervals versus precursors to depression.}
    \end{minipage}
\end{minipage}

here is my ugly result:

enter image description here

  • How to align captions? The table caption contains two rows and it goes up.
  • How to make the figure the same size as the table? Without chasing every single millimeter of its size.
  • How to crop white space around the figure (there is some distance between the caption and figure. I would like to 'zoom-in' the figure, to make it bigger.

EDIT

Thanks to great answer, but the figure is squashed. Any ideas?

enter image description here

  • In your edit, it looks as if you did not build the tabular with bottom alignment. In that case, \ht\mytablecontent will only obtain half of the required value, because the rest will be "depth" instead of "height". – Steven B. Segletes May 17 '17 at 11:11
  • Indeed, if I take my answer and remove the [b] from the tabular construction in \mytable, I get your edited figure aspect. So don't forget the [b] in your tabular construction. – Steven B. Segletes May 17 '17 at 11:19
2

I address the 3 issues of the OP in the following ways:

  1. I use 2 minipages foe each figure/table, with the \captionof placed under the content via \stackunder, so that the baselines of the two parts agree. Part of this also is to make tabular content with [b]ottom alignment (which is the alignment of \includegraphics).

  2. I save the tabular content in advance of the line construction, and use its height to set the height of the included graphic.

  3. The \stackunder takes an optional argument that sets the gap between the stacked items, in this case the content and the \captionof. Default is 3pt.

The MWE:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption,stackengine}
\begin{document}
\savestack\mytable{
    \begin{tabular}[b]{|c|c|c|}\hline
        Strategy        &  I     &  II   \\\hline
        precision$_0$   & 0.769  &  0.783\\
        precision$_1$   & 0.806  &  0.793\\
        recall$_0$      & 0.804  &  0.796\\  
        recall$_1$      & 0.769  &  0.774\\
        f$_1^{macro}$   & 0.788  &  0.786\\
        AUC             & 0.849  &  0.855\\\hline                 
    \end{tabular}
}
\begin{minipage}{\textwidth}
  \stackunder{\begin{minipage}[b]{0.49\textwidth}
    \centering
    \includegraphics[height=\ht\mytablecontent,
    width=0.6\linewidth]{figures/strategy_I_no_filter_ROC}
      \end{minipage}}
    {\begin{minipage}[b]{0.49\textwidth}
    \captionof{figure}{A figure beside a figure}
  \end{minipage}}
  \hfill
  \stackunder{\begin{minipage}[b]{0.49\textwidth}
    \centering
    \mytable
    \end{minipage}}
    {\begin{minipage}[b]{0.49\textwidth}
      \captionof{table}{Classification results of normal intervals versus precursors to depression.}
    \end{minipage}}
\end{minipage}
\end{document} 

enter image description here

  • many thanks, but surpassingly I get the figure squashed (please see the edited question) – Arnold Klein May 17 '17 at 11:02
  • @ArnoldKlein That is because I set both the height and the width of the \includegraphic (just to prove to myself that it centered relative to the caption). In general, just set the height=, and the width will be set to preserve the aspect. – Steven B. Segletes May 17 '17 at 11:08
  • amazing, I missed out the [b]. Now it works as charm. Thanks! – Arnold Klein May 17 '17 at 12:17
  • @ArnoldKlein You are welcome. That is one annoying aspect...that \includegraphics are bottom-aligned, whereas tabular is, by default, center-aligned. It causes no end of confusion. – Steven B. Segletes May 17 '17 at 12:20

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.