9

I am using KOMA-class. Let's say I want my chapter titles to look like this:

enter image description here

However the closest thing I can get is this:

enter image description here

The code I used is this:

\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*{\raggedsection}{\centering}
\renewcommand*{\chapterformat}{\adforn{36}\enskip\thechapter.\ }

\begin{document}

    \kant[1]

    \chapter{An Interesting Chapter Title}

    \kant[2]

    \begin{center}
        \vspace{\baselineskip}
        \scshape\large \adforn{36}\enskip 1. An Interesting Chapter Title\enskip\adforn{36}
        \\
        \rule{2em}{1pt}
    \end{center}

    \noindent\kant[3]


\end{document}

Things I already modified:

  1. The font for the chapter title.
  2. Centering.
  3. Not starting a new page.
  4. Vertical space before the title.

But I don't know how to add characters or even a new line after the actual chapter title is printed.

I would also like to know about further ways than those I already used, KOMA-classes provide to change chapter titles (whether it makes sense to use them is another thing).

Edit: As schtandard remarked, one has to make a decision how the title should look when it takes several lines. So let's see for example if we can get the following to work:

enter image description here

My code (which is certainly terrible):

    \begin{center}
        \vspace{\baselineskip}
        \scshape\large
        \adforn{36}\hspace{-1em}
        \parbox{11cm}{\centering 1. An Interesting Chapter Title Which is Way Too Long to Fit in One Line}
        \hspace{-1em}\adforn{36}
        \\[\baselineskip]
        \rule{2em}{1pt}
    \end{center}

Note that here the box has a fixed length of 11cm which is fine for taking the picture, but in practice, one should be able to specify a maximal width so that the box becomes shorter if the title is short.

9
  • Do you want to change the section or chapter titles?
    – Johannes_B
    Mar 18, 2018 at 9:59
  • @Johannes_B In my current document, it's the chapter titles, but I guess it will be rather similar.
    – user157036
    Mar 18, 2018 at 10:02
  • Do you only have chapter headings that fit in one line or do some of them break into several lines? If so, where should the ornaments go in that case?
    – schtandard
    Mar 18, 2018 at 10:44
  • @schtandard Good question, I did not think about that one yet. To make it more difficult, let's say the two lines of the chapter title should be put in a box with a defined maximal width and the ornaments should be left and right to that box, vertically centered. (Just trying to see what is possible here.)
    – user157036
    Mar 18, 2018 at 10:51
  • Then how do you want your titles to appear in the ToC?
    – remco
    Mar 18, 2018 at 10:59

3 Answers 3

7

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

3
  • Thank you. I think I really have to start reading also the Advanced part of the KOMA-script documentation. I will have a closer look at \chapterlinesformat. (I only changed the style of the chapters so as to avoid blank pages.)
    – user157036
    Mar 18, 2018 at 14:04
  • Is it possible to get rid of the indent in the very first paragraph of each chapter?
    – user157036
    Mar 18, 2018 at 14:31
  • Use beforeskip=-2\baselineskip (note the -). I have changed it in my answer.
    – esdd
    Mar 18, 2018 at 14:40
2
\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.

4
  • I am still trying to understand your code. For now I only realized that I can make the ornaments look misplaced if I call my chapter like this: \chapter{AnInterestingChapterTitleWhich isWayTooLongtoFitinOneLine} Do you have an idea about this?
    – user157036
    Mar 18, 2018 at 12:34
  • @JohnDorian what do you mean? For me, the ornaments appear in the exact same spot as in the image above (for chapter 2).
    – schtandard
    Mar 18, 2018 at 12:40
  • I mean that they are very far away from the title and don't always have a distance of, say 1em, to the title, as they have in one-line titles.
    – user157036
    Mar 18, 2018 at 12:44
  • That's right. I do not know if it is possible to determine the width of the text inside the \parbox (maybe somebody else does), so I decided to just place the ornaments 1em from the parbox (which should usually be fine, I think).
    – schtandard
    Mar 18, 2018 at 12:51
0

A bit of a hack, but one thing that worked for me for single line titles was adding

\newcommand{\mychapter}[1]{%
    \addtocounter{chapter}{1}%
    \chapter*{\chapterformat #1\enskip\adforn{36}}%
    \addcontentsline{toc}{chapter}{\thechapter.\ #1}
    \vspace{-2\baselineskip}%
    \begin{center}
        \rule{2em}{1pt}
    \end{center}
}

after '\renewcommand{\chapterformat}...'. And then of course use \mychapter instead of \chapter.
But I feel there must be a better way... (adding the formatting in a "\renewcommand{chapterlinesformat}" did not have any effect for me)

From what I've found, packages that allow adapting headers are usually limited to selecting fonts and font styles, they do not provide for modification of the chapter title contents, which is what you need here for the second leaf.

You must log in to answer this question.