[Tex/LaTex] Horizontal text alignment in captions for subfigures

captionshorizontal alignmentsubfloats

Captions in subfigures are justified by default, which does not always look pretty:

figure/subfigure caption alignment

\documentclass[]{tGIS2e} % http://www.tandf.co.uk/journals/authors/tgislatex.zip

\begin{document}

\begin{figure}
\begin{center}
%\raggedright
\subfigure{
    \includegraphics[draft,width=3cm,height=3cm]{dummy}%
    \label{fig:myfig_a}%
}
~
\subfigure[capture for b, justified]{
    \includegraphics[draft,width=3cm,height=3cm]{dummy}%
    \label{fig:myfig_b}%
}
~
\subfigure[justification becomes ugly sometimes]{
    \includegraphics[draft,width=3cm,height=3cm]{dummy}%
    \label{fig:myfig_c}%
}
~
\subfigure[there should be a way of applying \textbackslash raggedright or a similar command ]{
    \includegraphics[draft,width=3cm,height=3cm]{dummy}%
    \label{fig:myfig_d}%
}
\caption{Figure example}%
\label{fig:myfig}
\end{center}
\end{figure}

\end{document}

How would it be possible to keep the overall alignment of the image and its caption, and make the subcaption aligned, let’s say left? Adding \raggedright does not help — it shifts the whole image left, but keeps the alignment of the text.

It would be good if the solution exited for the markup given above, because the template I’m using does not support subfigure as environment and also conflicts with subcaption package.

Best Answer

Your documentclass is loading the (obsolete) subfigure package. This package has options such as raggedright for the caption justification. These options can be turned on locally by issuing e.g. \subcapraggedrighttrue:

Sample output

\documentclass[]{tGIS2e}

\begin{document}

\begin{figure}
\begin{center}
\subcapraggedrighttrue
\subfigure[caption for a]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_a}%
}
~
\subfigure[capture for b, justified]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_b}%
}
~
\subfigure[justification becomes ugly sometimes]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_c}%
}
~
\subfigure[there should be a way of applying \textbackslash raggedright or a similar command ]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_d}%
}
\caption{Figure example}%
\label{fig:myfig}
\end{center}
\end{figure}
\begin{figure}
\begin{center}
\subcapcentertrue
\subfigure[caption for a]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_a}%
}
~
\subfigure[capture for b, justified]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_b}%
}
~
\subfigure[justification becomes ugly sometimes]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_c}%
}
~
\subfigure[there should be a way of applying \textbackslash raggedright or a similar command ]{
    \includegraphics[width=3cm,height=3cm]{example-image-a}%
    \label{fig:myfig_d}%
}
\caption{Figure example}%
\label{fig:myfig}
\end{center}
\end{figure}
\end{document}

The list of possible commands includes

  • \subcapraggedrighttrue
  • \subcapcentertrue
  • \subcapcenterlasttrue

There are also false variants.

Similarly there is \subcaphangtrue to make sure the label sticks out to the left of the caption block. For example, in the above example

\subcapraggedrighttrue
\subcaphangtrue

give

Sample hang output

Also the nooneline option corresponds to \subcapnoonelinetrue. See the Declaration of Options section of the subfigure documentation, where you will as be able to deduce how to place captions above, rather than below the figures, etc.

Related Question