TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 enter image description here, 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?

share|improve this question
up vote 7 down vote accepted

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.

Added in your example:

\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}
share|improve this answer
    
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: enter image description here

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
\KOMAoption{captions}{tableheading,belowfigure}
\newcommand{\capsize}{\fontsize{8}{9.5}\selectfont}
\setkomafont{caption}{\capsize}
\setcapwidth[c]{.8\textwidth}
% --- following two change a lot, try
%\setcapindent{0pt}
%\addtokomafont{caption}{\centering}
\addtokomafont{captionlabel}{\bfseries}
% 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)
% last answer here:
% http://tex.stackexchange.com/questions/101595/how-to-add-line-break-to-caption-without-using-caption-package

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 :)

share|improve this answer
    
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

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.