[Tex/LaTex] Align figure next to table

floatstables

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

Best Answer

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