[Tex/LaTex] Setting the height of subfigure

subfloats

I want to include two subfigures in one figure.

I tried the following MWE. It works but I can't find out how to define the height of the subfigures (keeping their aspect ratios) without changing the width of the subcaptions.

\documentclass{memoir}
\usepackage{graphicx}

\newsubfloat{figure}

\begin{document}

\begin{figure}
  \begin{center}
    \begin{minipage}{\textwidth}
      \subbottom[A figure.]{\includegraphics[width=\textwidth]{file1}}
    \end{minipage} \\
    \begin{minipage}{\textwidth}
      \subbottom[Another figure.]{\includegraphics[width=\textwidth]{file2}}
    \end{minipage}
    \caption{Example of two figures.}
  \end{center}
\end{figure}

\end{document}

P.S.: How do I write MWEs that include graphics at TeX.SX? Without the included files, it isn't really a working example.

Best Answer

Something like this?

adjusted widths

The trick here is to put the full width minipage inside the sub-figure, so that the caption width is \textwidth, and to then set the horizontal alignment within each such environment:

\documentclass{memoir}
\usepackage{graphicx}

\newsubfloat{figure}

\begin{document}

\begin{figure}
  \centering
   \subbottom[A figure.]{%
     \begin{minipage}{\textwidth}
       \centering
       \includegraphics[width=\textwidth, height=10mm, keepaspectratio]{example-image-a}
     \end{minipage}%
   }\\
   \subbottom[Another figure.]{%
     \begin{minipage}{\textwidth}
       \centering
       \includegraphics[width=\textwidth, height=5mm, keepaspectratio]{example-image-b}
     \end{minipage}%
   }
    \caption{Example of two figures.}
\end{figure}

\end{document}

Note that \centering is better here than the center environment as the figure environment already introduces vertical space and we don't want the additional space which center includes.

Note that I've used example-image-a and example-image-b which are included in the mwe package and so everybody with a full TeX installation has them. (You don't need to load the package for the images to be available - they are deliberately installed so that they may be freely used. See the mwe package for additional images available in a variety of dimensions, formats, shapes and sizes.)

Related Question