# Linebreaks in KOMA-script captions

Using the captions package, linebreaks can be incorporated into figure-captions easily:

\documentclass[12pt]{book}

\usepackage{graphicx}
\usepackage{caption}

\begin{document}
\begin{figure}[htbp]
\begin{center}
\includegraphics{sampleImage.png}
\caption{First line of caption\\second line of caption\\third line of caption\\fourth line of caption}
\end{center}
\end{figure}

\end{document}


producing , with the line-breaks correctly observed.

Attempting something comparable with KOMA-script:

\documentclass[12pt]{scrbook}

\usepackage{graphicx}
\KOMAoption{captions}{belowfigure}

\begin{document}

\begin{figure}[htbp]
\begin{center}
\includegraphics{"sampleImage.png"}
\caption{First line of caption\\second line of caption\\third line of caption\\fourth line of caption}
\end{center}
\end{figure}

\end{document}


generates an error: Argument of \@caption has an extra }.

Is there another way to get line-breaks in a figure caption using KOMA-script?

-

The reason is, that by default KOMA-Script captions are put into horizontal boxes, to measure if they are longer than one line or not. That's why line breaks by \\ or \newline don't have effect. You can disable this default behavior, for example, by using the KOMA-Script option for captions nooneline, so "one-line" captions are treated like multi-line captions.

\KOMAoption{captions}{belowfigure,nooneline}


Then, you can get line breaks by \\ if you insert \protect before:

\caption{First line of caption\protect\\second line of caption}


However, it's not necessary if you specify an optional argument. It may be recommendable for such long captions, which might not be the optimum for the list of figures. So, this works too:

\caption[short caption]{First line of caption\\second line of caption}

-
Thank you. The use of the optional argument is especially useful. – brannerchinese Aug 6 '12 at 20:44

Thanks for all the tips, hints, and hacks I "exploited" so far and let me give this back. It cost me a lot of time to figure out the neat pitfalls and circumvent them:

I actually wanted to have exactly what OP asked but in addition the caption text should be aligned like this:

Unfortunately the nooneline-argument spoils it.

In the end I use this in my preamble:

%\KOMAoption{captions}{belowfigure,nooneline,tableheading}
% nooneline was necessary for linebreaks:
% cf.http://tex.stackexchange.com/questions/66111/linebreaks-in-koma-script-captions
\newcommand{\capsize}{\fontsize{8}{9.5}\selectfont}
\setkomafont{caption}{\capsize}
\setcapwidth[c]{.8\textwidth}
% --- following two change a lot, try
%\setcapindent{0pt}
% cf. here: http://tex.stackexchange.com/questions/66116/puzzled-as-to-centering-of-koma-script-captions
% cf. for multiline solution --> avoiding nooneline (because it uncenters the caption)


and then in the document:

\begin{figure}[htbp]
\begin{center}
\rule{2cm}{2cm}
\caption[Some caption short]{\tabular[t]{@{}l@{}}Some caption foobarbuz \\ source: Here and There\endtabular}
\end{center}
\end{figure}


Have fun :)

-
This doesn't answer direct question, but rather a way to provide an alternative layout/horizontal alignment of the caption. – Werner Feb 15 at 19:15
I guess both lie close to one another and as I couldn't find an answer to my not that far-fetched question I wanted to share it. – MaK Feb 16 at 0:09
@MaK Since this answers a slightly different question, it will probably be hard to find for other people with this problem. How about you ask it as a new question and provide this as an self answer to the new question? – samcarter Feb 16 at 17:49
@samcarter done :) thanks for your kind advice – MaK Feb 16 at 18:28