2
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}
% \usepackage{ragged2e} % required by `'\captionsetup{justification=RaggedRight}`', but that doesn't move the caption itself.

\begin{document}

\begin{figure}
    \centering
    \begin{subfigure}{0.4\textwidth}
        \includegraphics[width=1.0\textwidth]{example-image-a}
        \captionsetup{skip=-12pt}
        \caption{}
        \label{fig:a}
    \end{subfigure}
    \begin{subfigure}{0.4\textwidth}
        \includegraphics[width=1.0\textwidth]{example-image-b}
        \captionsetup{skip=-12pt}
        \caption{}
        \label{fig:b}
    \end{subfigure}
\end{figure}

\end{document}

produces

enter image description here

but I would instead like the subcaption text (a) and (b) to be left-justified within the image.

There are other questions that use the stackengine package, or require manually labeling the figures, and I am looking for an alternative approach.

If there is a better alternative to specifying skip=-12pt, I'd also like to know.

EDIT:

I had tried to set the justification with \captionsetup within the subfigure, but if I place the following line in the preamble

\captionsetup[subfigure]{justification=justified,singlelinecheck=false}

I get a better starting point:

enter image description here

Gus
  • 1,217

1 Answers1

5
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption,subcaption}

\begin{document}

\begin{figure}
    \centering
    \captionsetup[subfigure]{skip=-12pt, margin=3pt, singlelinecheck=false}  % <---
    \begin{subfigure}{0.4\textwidth}
        \includegraphics[width=1.0\textwidth]{example-image-a}
        \caption{}
        \label{fig:a}
    \end{subfigure}
    \begin{subfigure}{0.4\textwidth}
        \includegraphics[width=1.0\textwidth]{example-image-b}
        \caption{}
        \label{fig:b}
    \end{subfigure}
\end{figure}

\end{document}

gives:

enter image description here

Zarko
  • 296,517
  • Thanks! To clarify, margin is responsible for the caption being left-aligned? – Gus May 30 '21 at 21:00
  • @gus, I use it to move caption labels a bit to the right. – Zarko May 30 '21 at 21:39
  • I did not realize that this method relied on the caption being at the bottom. I've asked a follow-on question here: https://tex.stackexchange.com/questions/621260/position-subcaption-within-subfigure-at-the-top-inset – Gus Nov 04 '21 at 00:20