9

I found an asnwered question concerning this topic already here: Centering a subcaption Copying \captionsetup[subfigure]{justification=centering} doesn't help me thought for I am using different packages.

I would like my Captions and Subcaptions to be justified as the text below. Just under my pictures. Any suggestions?

Thanks a lot

\documentclass{article}
\usepackage{subfig}
\usepackage[labelfont=bf, justification=justified]{caption}
\usepackage[demo]{graphicx}% Remove demo option in real document

\begin{document}    
\begin{figure}
%   \captionsetup[subfigure]{justification=centering}
    \centering  
    \subfloat[Subcaption one \newline including a linebreak ]   {
    \includegraphics[width=0.2\textwidth]{image1}
    }
    \hspace{1cm}
    \subfloat[Subcaption two \newline including a linebreak]
    {
    \includegraphics[width=0.2\textwidth]{image2}
    }   
    \caption{Figure caption \newline with additional text right here}
\end{figure}

\begin{center}
This is correctly justified Text \\ including a longer linebreak than blabla.
\end{center}
\end{document}
3
  • Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Jan 21, 2014 at 18:47
  • Does my answer solve your problem? Commented Jan 22, 2014 at 15:16
  • Happy to help :-) Commented Jan 23, 2014 at 12:16

1 Answer 1

12

The command \subfloat has two optional arguments, the first being the LoF entry.

So, substituting lines like

\subfloat[Subcaption one \newline including a linebreak]

with

\subfloat[Subcaption one including a linebreak][Subcaption one \\ including a linebreak]

does the job.

MWE (I've also removed some spurious spaces with %)

\documentclass{article}
\usepackage{subfig}
\usepackage[labelfont=bf, justification=justified]{caption}
\usepackage[demo]{graphicx}% Remove demo option in real document

\begin{document}
\begin{figure}
   \captionsetup[subfigure]{justification=centering}
    \centering
    \subfloat[Subcaption one including a linebreak][Subcaption one \\ including a linebreak]
    {%
    \includegraphics[width=0.2\textwidth]{image1}%
    }%
    \hspace{1cm}%
    \subfloat[Subcaption two including a linebreak][Subcaption two \\ including a linebreak]
    {%
    \includegraphics[width=0.2\textwidth]{image2}%
    }
    \caption{Figure caption \\ with additional text right here}
\end{figure}

\begin{center}
This is correctly justified Text \\ including a longer linebreak than blabla.
\end{center}

\end{document}

Output:

enter image description here

1
  • Do you have to do anything special to allow \` in the subcaptions? I get errors whereas \newline` works fine. This is in a rather complex document so I just wondered if there's anything I can check for easily as I've never used subfig before. (If not, I might try to create an MWE but I'll probably just use \newline even if I really ought not.)
    – cfr
    Commented May 21, 2014 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .