Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
2  
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

1 Answer 1

up vote 6 down vote accepted

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}

enter image description here

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

share|improve this answer
    
Thank you very much! This solved my problem! –  Cari Baur Apr 30 '13 at 15:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.