1

I've got three figures that I place vertically on a half page.

\begin{figure}
\includegraphics[width=0.4\textwidth]{images/fig1a.png}
\includegraphics[width=0.4\textwidth]{images/fig1b.png}
\includegraphics[width=0.4\textwidth]{images/fig1c.png}
\end{figure}

I want to subnumber them and put the (a), (b) and (c) at the corners of the images. All three figures are of different resolutions and sizes. It's hard do that and get them vertically aligned in the resulted pdf. So, my question is if there is a proper tool or package to do this automatically?

Regards Ilya

  • 3
    Welcome to TeX SX! Try the subfigure environment, from the subcaption package. – Bernard Nov 9 '18 at 22:54
  • Which corner? Lower left is easiest. – John Kormylo Nov 10 '18 at 4:34
  • Ideally upper right or left. – Ilya Bryukhanov Nov 10 '18 at 6:44
1

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}

demo


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}

demo 2

  • You write "The subfig package does this automatically". This is true, but the subcaption package does this automatically, too, when \subcaptionbox is used instead of the subfigure environment. – Axel Sommerfeldt Nov 10 '18 at 21:11
  • @AxelSommerfeldt - Ah yes. An even better reason to stop using subfig. – John Kormylo Nov 11 '18 at 14:43
0

I think the simplest of all methods is to use the subfigure package, that adjusts to the desired dimensions of your images, althought it has problems with tikz, so I avoid it, but it works wonderfully with imported graphics

\documentclass{article}
\usepackage{graphicx,subfigure}
\begin{document}
\begin{figure}
\centering
\subfigure[Subcaption a.]{\includegraphics[width=.6\textwidth]{example-image-a}}
\subfigure[Subcaption b.]{\includegraphics[width=.6\textwidth]{example-image-b}}
\subfigure[Subcaption c.]{\includegraphics[width=.6\textwidth]{example-image-c}}
\caption{Caption}
\end{figure}
\end{document}

enter image description here

  • subfigure is obsolete package. instead of it is suggested to use the subfig package. – Zarko Dec 11 '18 at 22:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.