Ways to modify chapter titles in KOMA-class

If you use style=section for chapters then you have to redefine \sectionlinesformat to change the layout for chapter titles:

\documentclass{scrbook}
\usepackage{kantlipsum} %providing dummy text
\usepackage{adforn} %providing ornaments

\RedeclareSectionCommand[style=section,indent=0pt,beforeskip=-2\baselineskip]{chapter}
\setkomafont{chapter}{\normalfont\large\scshape}
\renewcommand*{\raggedchapter}{\centering}

\usepackage{varwidth}
\makeatletter
\renewcommand\sectionlinesformat[4]{%
  \ifstr{#1}{chapter}
    {%
      \raggedchapter
      \adforn{36}\enskip
      \begin{varwidth}{\dimexpr\textwidth-6em\relax}
        \raggedchapter#3#4%
      \end{varwidth}%
      \enskip\adforn{36}%
      \par\nobreak
      \strut\rule{2em}{1pt}%
      \par
    }
    {\@hangfrom{\hskip#2#3}{#4}}% original definition for other section levels
}
\makeatother

\begin{document}
\kant[1]
\chapter{An Interesting Chapter Title}
\kant[2]
\chapter{An Interesting Chapter Title Which is Way Too Long to Fit in One Line}
\kant[3]
\end{document}

enter image description here


\documentclass{scrbook}

\usepackage{etoolbox}

\usepackage{kantlipsum} %providing dummy text
\usepackage{adforn} %providing ornaments

\makeatletter
    % \RedeclareSectionCommand[beforeskip=2\baselineskip]{chapter} % <-- this seems too little
    \setkomafont{chapter}{\normalfont\large\scshape}
    \renewcommand*{\raggedchapter}{\centering}
    \renewcommand*{\chapterformat}{\thechapter.\ }
    \patchcmd\scr@startchapter{\if@openright\cleardoublepage\else\clearpage\fi}{}{}{}

    \newbox\@chapter@heading@testbox
    \renewcommand\chapterlinesformat[3]{%
        \savebox\@chapter@heading@testbox{#2#3}%
        \ifdim\wd\@chapter@heading@testbox>\dimexpr\linewidth-6em\relax
            \raggedchapter
            \adforn{36}\hskip 1em%
            \parbox{\dimexpr\linewidth-6em}{%
                \raggedchapter
                #2#3
            }%
            \hskip 1em\adforn{36}
            \@@par
        \else
            \parbox{\linewidth}{%
                \raggedchapter%
                \adforn{36}\hskip 1em%
                {\let\@@par\relax
                    #2#3%
                }%
                \hskip 1em\adforn{36}%
            }%
            \@@par
        \fi
        \raggedchapter\strut\rule{2em}{.4pt}\par%
    }
\makeatother

\begin{document}

\kant[1]

\chapter{An Interesting Chapter Title}

\kant[2]

\chapter{An Interesting Chapter Title Which is Way Too Long to Fit in One Line}

\kant[3]

\end{document}

the output of the code above

What is happening here?

  • Chapter is not redeclared to be of type section.
  • The pagebreaks are instead avoided by removing the appropriate code from \scr@startchapger using \patchcmd from etoolbox.
  • We now use \chapterlinesformat to format the chapter heading (#2 contains the formatted chapter number, #3 the formatted chapter title).
  • We first check if the heading is longer than one line and then typeset it accordingly.
  • #3 contains a \@@par. Since we want to have the second ornament on the same line as the title, we need to deactivate it before typesetting in the case of a single line heading.
  • The \strut on the line with the \rule makes sure it has the correct distance from the heading in the case of multiple lines.

Please note that as a consequence of centering your headings, the second (and subsequent) lines of the chapter title may flow below the chapter number.