# Centering a subcaption

I have three figures that I want to place next to each other. That is fine. In addition, however, each subfigure has a caption on its own and the crucial thing with these is that I have to have two lines for each of them generated by a linebreak. I managed that using \newline, but now the subcaption always starts on the left edge of the subfigures and is not centered any more (which does not look nice).

What can I do to resolve my problem?

\documentclass{scrartcl}
\usepackage{graphix,subcaption}

\begin{document}
\begin{figure}[t]
\centering
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{\centering Nice image1.\newline Another line.}
\label{fig:NiceImage1}
\end{subfigure}
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{\centering Nice image 2.\newline Another line.}
\label{fig:NiceImage2}
\end{subfigure}
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{\centering Nice image 2.\newline Another line.}
\label{fig:NiceImage3}
\end{subfigure}

-
Welcome to TeX.SE! have you tried adding \centering inside each subfigure? –  cmhughes Apr 30 '13 at 14:11
@cmhughes since the subfigures occupy all the available width of their corresponding subfigure environment, \centering won't have any effect. Besides, \centering doesn't affect the caption which is the problem here. –  Gonzalo Medina Apr 30 '13 at 15:06

You can use justification=centering for \captionsetup:

\documentclass{scrartcl}
\usepackage[demo]{graphicx}
\usepackage{subcaption}

\begin{document}
\begin{figure}
\captionsetup[subfigure]{justification=centering}
\centering
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{Nice image1. \\ Another line.}
\label{fig:NiceImage1}
\end{subfigure}
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{Nice image 2. \\ Another line.}
\label{fig:NiceImage2}
\end{subfigure}
\begin{subfigure}{0.31\textwidth}
\includegraphics[width=\textwidth]{image1}
\caption{Nice image 3. \\ Another line.}
\label{fig:NiceImage3}
\end{subfigure}
\end{figure}

\end{document}


The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

-
Thank you very much! This solved my problem! –  Cari Baur Apr 30 '13 at 15:54