[Tex/LaTex] Puzzled as to “centering” of KOMA-script captions

captionshorizontal alignmentkoma-script

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

Best Answer

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.

Related Question