1

I am repeating an example shown previously in One figure having two columns of subfigures: the left column has one image and the right one has two images , but with the use of subcaption package.

Finally, I got one failed version and one successful version. My question is, why do I fail for the first version (getting the wrong height of minipage with subfigure environment inside)?

The failed version

% The failed version
\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\newsavebox{\measurebox}
\begin{document}
    \begin{figure}
        \centering
        \sbox{\measurebox}{%
            \begin{minipage}[b]{.33\textwidth}
                \begin{subfigure}{\textwidth}
                    {\includegraphics[width=\textwidth,height=5cm]{figA}\caption{caption A}}
                \end{subfigure}
              \end{minipage}}
        \fbox{\usebox{\measurebox}}\qquad
        \fbox{%
            \begin{minipage}[b][\ht\measurebox][s]{.33\textwidth}
                \centering
                \begin{subfigure}{\textwidth}
                    \includegraphics[width=\textwidth,height=2cm]{figB}\caption{caption B}
                \end{subfigure}
                \vfill
                \begin{subfigure}{\textwidth}
                    \includegraphics[width=\textwidth,height=2cm]{figC}\caption{caption C}
                \end{subfigure}
            \end{minipage}%
        }
        \caption{my caption}
    \end{figure}
\end{document}

Successful version

% The successful version
\documentclass{article}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\newsavebox{\measurebox}
\begin{document}
    \begin{figure}
        \centering
        \sbox{\measurebox}{%
            \begin{minipage}[b]{.33\textwidth}
                \includegraphics[width=\textwidth,height=5cm]{figA}\subcaption{caption A}
            \end{minipage}}
        \fbox{\usebox{\measurebox}}\qquad
        \fbox{%
            \begin{minipage}[b][\ht\measurebox][s]{.33\textwidth}
                \centering
                \includegraphics[width=\textwidth,height=2cm]{figB}\subcaption{caption B}
                \vfill
                \includegraphics[width=\textwidth,height=2cm]{figC}\subcaption{caption C}
            \end{minipage}%
        }
        \caption{my caption}
    \end{figure}
\end{document}
Dau Zi
  • 392
  • 1
    The subfigure is also a minipage, which defaults to [c]. It has a height of 82pt and a depth of 77pt. The outer minipage only has one baseline to use. [b] uses the bottom baseline, [t] uses the top baseline, but in this case it doesn't make any difference. If you aren't absolutely sure the depth is 0pt, use \dimexpr \ht\measurebox+\dp\measurebox. – John Kormylo Oct 29 '19 at 03:20
  • Thanks for the hint on treating subfigure as minipage. Actually for version 2, I could directly replace minipage with subfigure. Besides, I found that the savebox in version 1 only captures the default 82pt height (and 77pt depth) of the outer minipage but not the real one. When I use \dimexpr \ht\measurebox+\dp\measurebox, it has the same effect of having 159pt. So does that mean we cannot capture the height of a minipage if there is an inner minipage within it? – Dau Zi Oct 29 '19 at 16:00
  • Height is the distance from the top to the baseline, not top to bottom. The latter is sometimes called totalheight (see calc package). – John Kormylo Oct 29 '19 at 16:08

0 Answers0