I've done some styling for my chapter titles, based upon tikz and the titlesec package.
Unfortunately, the KOMA-Script packages gives me numerous warnings about titlesec. In order to get rid of the titlesec-package, I've tried to accomplish the same chapter style with the build-in \chapterformat
of KOMA-Script. This works quite well, until I noticed that the \chapter*
-like headings (e.g. TOC and so on) were not affected.
After doing some research, I've found the – trivial – reason for this behaviour. \chapterformat
affects only the number part of the title. All the \chapter*
have no chapter number, so \chapterformat
does not work.
The Question
Is it possible to format both \chapter and \chapter* with pure KOMA-Script, or does this require titlesec or a similar package?
MWE
\documentclass{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{tikz}
\usepackage[T1]{fontenc}
\renewcommand{\chapterformat}{
\begin{tikzpicture}[remember picture,overlay]
\draw[fill=gray,draw=none] (0,0) rectangle (1cm,1cm);
\end{tikzpicture}
\thechapter
}
\begin{document}
\chapter{The Chapter}
\blindtext
\chapter*{The Chapter without number}
\blindtext
\end{document}
compiled MWE
Just for info
This is maybe not really part of the question, however that's the current \chapter
style in my document. \chapter*
should have the same position and background, without the orange bar. The one above is only a MWE for demo purposes.
Best Answer
Since KOMA-Script version 3.19 the command
\chapterlinesformat
can be redefined to change the layout of chapter titles which have no prefix line. Now it is possible to position the chapter title in a graĆ½ box on top of the page without usingscrlayer-scrpage
. And chapter titles with more than one line are possible.Run twice (because of
\Ifthispageodd
) to get