There are a few details which can be painful to discover, since some are from the caption manual. The blank lines (\par
) are needed to keep them from winding up side by side.
You said different sizes. Although the MWE uses known sizes, this will work for images with unknown sizes. \subcaptionbox
does this automatically (thank you Alex Sommerfelt for pointing this out), but it is no big deal. All subfigures are basically minipages with captions.
\documentclass{article}
\usepackage[singlelinecheck=off]{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{}{\includegraphics[width=0.4\textwidth]{example-image-a}}
\sbox0{\includegraphics[width=0.4\textwidth]{example-image-b}}% measure width
\begin{subfigure}{\wd0}
\usebox0
\caption{}
\end{subfigure}
\sbox0{\includegraphics[width=0.4\textwidth]{example-image-c}}% DIY caption
\begin{minipage}{\wd0}
\leavevmode\llap{(c)~}% left
\usebox0
(c)
\end{minipage}
\caption{There is usually one of these too.}
\end{figure}
\end{document}
These solutions puts the subcaption at the upper right corner.
\documentclass{article}
\usepackage[singlelinecheck=off,justification=raggedleft,position=top]{subcaption}
\usepackage{graphicx}
\begin{document}
\begin{figure}
\centering
\subcaptionbox{}{\includegraphics[width=0.4\textwidth]{example-image-a}}
\sbox0{\includegraphics[width=0.4\textwidth]{example-image-b}}% measure width
\begin{subfigure}{\wd0}
\caption{}
\usebox0
\end{subfigure}
\sbox0{\includegraphics[width=0.4\textwidth]{example-image-c}}% DIY caption
\begin{minipage}{\wd0}% in case you want to align side by side
\strut\makebox[\wd0][r]{(c)}\par% above
\usebox0%
\rlap{\raisebox{\dimexpr \ht0-\topskip}{(c)}}% right
\end{minipage}
\caption{There is usually one of these too.}
\end{figure}
\end{document}
subfigure
environment, from thesubcaption
package.