1

I am trying to have a figure and a table side by side using minipage. When I use \caption instead of using \captionof then the table caption starts with Fig. If the table caption is above the table then the table slides down.

enter image description here

\begin{figure*}
    \centering
    \begin{minipage}[b]{0.6\textwidth}
        \includegraphics[width=0.9\textwidth]{state-transistion}
        \captionof{figure}{State Transition}
        \label{fig:state-transition}
    \end{minipage}%
    \begin{minipage}[b]{0.3\textwidth}
        \centering
        \captionof{table}{Some Table}%
        \label{table:iterator}%
        \begin{tabular}{l|l}
            \hline
            X & x \\ \hline
            A & a \\
            B & b \\
            C & c
        \end{tabular}
    \end{minipage}
\end{figure*}

Everything works fine if the table caption is below the table.

enter image description here

But I need to place the table caption above the table without wasting that space. Also I don't understand why these is too much space above the Figure caption, but not above the table caption. This is not a big concern though.

2 Answers 2

1

With top aligned minipages and valign=t from the adjustbox package:

enter image description here

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[export]{adjustbox}
\usepackage{caption}
\begin{document}
\begin{figure*}
    \centering
    \begin{minipage}[t]{0.6\textwidth}
        \includegraphics[width=0.9\textwidth,valign=t]{state-transistion}
        \captionof{figure}{State Transition}
        \label{fig:state-transition}
    \end{minipage}%
    \begin{minipage}[t]{0.3\textwidth}
        \centering
        \captionof{table}{Some Table}%
        \label{table:iterator}%
        \begin{tabular}{l|l}
            \hline
            X & x \\ \hline
            A & a \\
            B & b \\
            C & c
        \end{tabular}
    \end{minipage}
\end{figure*}
\end{document}
5
  • This solution of using valign=t works, if the first minipage has only one graphics. But in another case, my first minipage includes two subfigures each including an \includegraphics. I put valign=t in both of these two includegraphics. But that didn't work.
    – Neel Basu
    Mar 30, 2020 at 20:09
  • Are the subfigures next to each other or above of each ither? How did you include them? (subcaption package, subfig package, something else)? Please clarify.
    – leandriis
    Mar 30, 2020 at 20:11
  • The \subfigures are next to each other (using subcaption package). There is a figure* environment that contains two minipage. The first minipage contains two \begin{subfigure}{0.45\textwidth} ... \end{subfigure}s each of which contains a \includegraphics[width=\textwidth, valign=t]{...}. The second minipage contains a table that has \captionof{table}{...} above the tabular.
    – Neel Basu
    Mar 30, 2020 at 20:18
  • Thanks for the clarification. You could try with \begin{minipage}[t] for the minipage containing the subfigures and \begin{minipage}[b] for the minipage containing the table.
    – leandriis
    Mar 30, 2020 at 20:22
  • Thanks that worked.
    – Neel Basu
    Mar 30, 2020 at 20:24
2

Here's another approach using the floatrow package:

float

\documentclass{article}
\usepackage{graphicx}
\usepackage{floatrow}
\begin{document}
\begin{figure*}
    \CenterFloatBoxes
    \begin{floatrow}
        \ffigbox[\FBwidth]
            {\includegraphics[width=0.54\textwidth]{example-image}}
            {\caption{State Transition}%
            \label{fig:state-transition}}
        \killfloatstyle\ttabbox[\Xhsize]
            {\caption{Some Table}%
            \label{table:iterator}}
            {\begin{tabular}{l|l}
            \hline
                X & x \\ \hline
                A & a \\
                B & b \\
                C & c
            \end{tabular}}
    \end{floatrow}
\end{figure*}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .