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?
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:Note that
\centering
is better here than thecenter
environment as thefigure
environment already introduces vertical space and we don't want the additional space whichcenter
includes.Note that I've used
example-image-a
andexample-image-b
which are included in themwe
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 themwe
package for additional images available in a variety of dimensions, formats, shapes and sizes.)