[Tex/LaTex] Left-align captions with respect to subfigure

captionshorizontal alignmentsubcaption

How do I left-align the captions on the subfigures below, so that the caption starts aligned with the left-hand edge of the corresponding subfigure?

enter image description here

\documentclass{article}

\usepackage[draft]{graphicx}
\usepackage{subcaption}

\begin{document}

\begin{figure}[H]
\begin{center}
\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[scale=0.8]{fig/workflow-S}
\caption{workflow $S$}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
\includegraphics[scale=0.8]{fig/workflow-S-run}
\caption{run of $S$}
\end{subfigure}

\begin{subfigure}[b]{0.3\textwidth}
\includegraphics[scale=0.8]{fig/workflow-S'}
\caption{workflow $S'$}
\end{subfigure}
\begin{subfigure}[b]{0.5\textwidth}
\includegraphics[scale=0.8]{fig/workflow-S'-run}
\caption{run of $S'$}
\end{subfigure}
\end{center}
\end{figure}

\end{document}

There seem to be many related questions, but none that specifically addresses this.

Best Answer

Add this line to your preamble,

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

That will affect all the subfigure captions. For details (and other options), please keep reading on.


As is pointed out in the caption package documentation,

As addition to the caption format you could also specify a caption justification; it is specified with the option justification=<justification name>.

You can choose one of the following:

justified: Typesets the caption as a normal paragraph.

......

singlelinecheck= The standard LaTeX document classes (article, report, and book) automatically center a caption if it fits in one single line. The caption package adapts this behavior and therefore usually ignores the justification & indention you have set with justification= & indention= in such case. But you can switch this special treatment of such short captions off with the option singlelinecheck=false.

Now since you want only the subfigure captions to be left justified, you need to use the \captionsetup[FLOAT_TYPE]{OPTIONS} command.

FLOAT_TYPE can be table, figure, subtable and subfigure and specifies what type of caption that particular \captionsetup command applies to. So you can set different options for each of the figure, table, subfigure and subtable floats individually.

In your case the FLOAT_TYPE will be subfigure. If you put that \captionsetup command in the preamble, all your subfigure captions will be left justified. If you put that at some midpoint, all subsequent ones will get that effect. Should you need that for only one figure, put that inside that particular figure environment.


Here is the output.

enter image description here