1

I want to insert a manual line break in the subfigures captions. I have achieved this with either \protect\\ or \newline. However, the second lines do not align properly. I want them to start at the same horizontal position as the text (not the number) of the first line.

Here is an MWE:

\documentclass[a4paper,12pt,openright,oneside,bibliography=totoc,headsepline]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage[config=altsf]{subfig}
\usepackage{graphicx}
\usepackage{mwe}


\begin{document}

\begin{figure}
    \captionsetup[subfloat]{format=hang,singlelinecheck=false,justification=RaggedRight}
    \centering
    \subfloat[line break should \protect\\ be here]{\includegraphics[scale=0.5]{example-image-a}}
    \newline
    \subfloat[newline \newline there]{\includegraphics[scale=0.5]{example-image-a}}
    \caption{Test figure.}
\end{figure}

\end{document}

The output looks like this: enter image description here

First, the second line is not aligned like the first one (seems to be centered) and second, why are the two images not aligned? How can I achieve a line break and a hanging alignment of the second line? So, for subfigure (a) the "b" of the second line should be (horizontally) where the "l" is from the first line. An ugly workaround would be to set \hspace to an appropriate value instead of using a line break command. But I hope there is a better solution.

0

It seems that the problem is that singlelinecheck=false doesn't work if the subfig package is loaded with the option [config=altsf]. So I didn't use it:

\documentclass[a4paper,12pt,openright,oneside,bibliography=totoc,headsepline]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage
%[config=altsf]
{subfig}
\usepackage{graphicx}
\usepackage{mwe}


\begin{document}


\begin{figure}
    \captionsetup[subfloat]{margin=10pt,format=hang,singlelinecheck=false,justification=RaggedRight}
    \centering
    \subfloat[line break should \protect\\ be here]{\includegraphics[scale=0.5]{example-image-a}}

    \subfloat[newline \newline
    there]{\includegraphics[scale=0.5]{example-image-a}}
    \caption{Test figure.}
\end{figure}



\end{document}

enter image description here

  • Thanks! I would like to keep the old package as well. I have a lot of figures and only recently switched to the newer 'subfig' package and I do not want to reorientate all the older figures using the 'subfigure' package so that they would look with the newer 'subfig' package as they do now. – aquila Jan 24 at 15:27
  • Hi @aquila I am not suggesting to switch to subfig! It was already used in your code. – Hafid Boukhoulda Jan 24 at 15:35
  • Hi @Hafid Boukhoulda, you are right. But without the option [config=altsf] my older figures using the subfigure command will not work anymore and it will not compile until I change them to subfloat. Or do I miss something? Maybe, I should change them it subfloat and realign them again. – aquila Jan 24 at 22:01
  • @aquila Do you mean that you use both subfig and subfigure packages in the same file ? – Hafid Boukhoulda Jan 25 at 7:15
  • Yes, I have been using both commands. Now I changed all \subfigure commands to \subfloat. And the caption alignment now works. Thanks for your help! – aquila Jan 25 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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