4

Section 3.20 of the KOMA-script documentation ("scrguien.pdf", pp. 120-1) prescribes the syntax \setcapwidth[justification]{width} for the formatting of a caption. [c] is the option for centering.

Trying to produce the same output I get from the use of the caption package with options for justification and width, I'm surprised to see that the justification is quite different: KOMA-script produces a hanging caption that is justified, rather than centered in the strict sense.

My question: is there a way to produce the same output as in the caption example: centered and not hanging?

Examples follow, with an absurdly long caption to highlight the difference:

caption

\documentclass[12pt]{book}

\usepackage{graphicx}
\usepackage{lipsum}
\usepackage[justification=centering,width=.8\textwidth]{caption}

\begin{document}

\begin{figure}[htbp]
  \begin{center}
   \includegraphics{imageTest.png}
   \caption{\protect\lipsum[1]}
  \end{center}
\end{figure}

\end{document}

Output: enter image description here


KOMA-script

\documentclass[12pt]{scrbook}

\usepackage{graphicx}
\usepackage{lipsum}

\KOMAoption{captions}{belowfigure}
\setcapwidth[c]{.8\textwidth}

\begin{document}

\begin{figure}[htbp]
  \begin{center}
   \includegraphics{"imageTest.png"}
   \caption[short caption]{\lipsum[1]}
  \end{center}
\end{figure}

\end{document}

Output: enter image description here

8

The horizontal centering of the text can be achieved by setting the indentation below the caption label to 0 pt and adding \centering to the font format of the caption:

\documentclass[12pt]{scrbook}

\usepackage{graphicx}
\usepackage{lipsum}

\setcapwidth[c]{.8\textwidth}
\setcapindent{0pt}
\addtokomafont{caption}{\centering}

\begin{document}

\begin{figure}[htbp]
  \begin{center}
   %\includegraphics{"imageTest.png"}
   \rule{2cm}{2cm}
   \caption[short caption]{\lipsum[1]}
  \end{center}
\end{figure}

\end{document}

The optional argument for \setcapwidth controls the alignment of the complete caption, not the justification of the caption text.

-1

In case you want to be able to set line-breaks as well see my answer here:

tex stackexchange

(Using bits and pieces I found around here and piecing them together.)

  • 1
    merging done ;) – MaK Feb 16 '16 at 0:07

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.