# Horizontal text alignment in captions for subfigures

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

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

\begin{document}

\begin{figure}
\begin{center}
%\raggedright
\subfigure[caption for a]{
\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.

• It is not clear, do you want all the captions \raggedright or are you merely asking for caption (a) to be left-aligned? Or both? – Steven B. Segletes Jan 28 '14 at 18:32
• Ideally I want to control the alignment of every caption, but if not, simply making all captions aligned left would be enough. I pretty much dislike unnecessarily large spaces between words, it frequently happens when text is justified. This slows down reading. – Alexander Kachkaev Jan 28 '14 at 18:34
• Please provide a minimal working example (MWE) so that we can see which package or documentclass is defining your \subfigure command. – Andrew Swann Jan 28 '14 at 18:36
• @AndrewSwann, done. Sorry for forgetting to include documentclass into my example. – Alexander Kachkaev Jan 28 '14 at 18:43
• You can use tabular instead of subfigure. A multiline caption can be implemented using a p{} field, or putting a \parbox inside a c field. – John Kormylo Jan 28 '14 at 19:07

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:

\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

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.

• This works great! By the way, are there any options to make all caption text appear on the right from the label (a, b, c) like in the answer by @steven-b-segletes, but without a need to define the width manually? – Alexander Kachkaev Jan 28 '14 at 19:14
• @AlexanderKachkaev Sure. Explanation added. – Andrew Swann Jan 28 '14 at 19:26
• do you know by a chance what command in subcaption+floatrow packages does the same as \subcaphangtrue in subfigure? – Alexander Kachkaev Apr 11 '14 at 17:25

If you don't mind the captions being offset relative to the (a), (b), ... labels and don't mind specifying the caption width, then this could work.

\documentclass{article}
\usepackage{subfigure}
\usepackage[demo]{graphicx}
\textwidth 6in
\newcommand\tparbox[2]{\protect\parbox[t]{#1}{\protect\raggedright #2}}
\begin{document}
\begin{figure}
\begin{center}
\subfigure[\tparbox{2.5cm}{caption for a}]{
\includegraphics[draft,width=3cm,height=3cm]{dummy}%
\label{fig:myfig_a}%
}
~
\subfigure[\tparbox{2.5cm}{capture for b, justified}]{
\includegraphics[draft,width=3cm,height=3cm]{dummy}%
\label{fig:myfig_b}%
}
~
\subfigure[\tparbox{2.5cm}{justification becomes ugly sometimes}]{
\includegraphics[draft,width=3cm,height=3cm]{dummy}%
\label{fig:myfig_c}%
}
~
\subfigure[\tparbox{2.5cm}{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}