How does one apply a custom styling to the chaptertitle in KOMA-Script? I know about the existence of the titlesec package but I've read that it doesn't play very well with KOMA-Script which outputs a warning. Therefore my idea was to style the chapter page soley with the help of KOMA-Script functionality.
I've read some posts about styling chapters and came up with the following code:
\documentclass[english]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\KOMAoption{chapterprefix}{true}
% centering the chapter head
\let\raggedchapter\centering
\setkomafont{chapterprefix}{\normalsize\mdseries}
% This block has the two variables \chapapp and \thechapter. But where
% can I find a variable for the title of the chapter (eg. \chaptertile) to apply some styling?
\renewcommand*{\chapterformat}{%
\MakeUppercase{\chapapp}~\thechapter\\[-0.6\baselineskip]
\noindent\makebox[\textwidth]{%
\rule{0.9\textwidth}{.5pt}%
}%
}
% If I use this line for styling the title of the chapter - I get an error
% \addtokomafont{chapter}{\MakeUppercase}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=8\baselineskip]{chapter}
\begin{document}
\blinddocument
\end{document}
Using \renewcommand*{\chapterformat}
does work for styling the \chapapp~\thechapter
which correctly outputs "Chapter 1". What I have not found is a variable similar to \chapapp
or \thechapter
which holds the chapter title and can be used to style the title, like assigning uppercase a.s.o.
I have found \addtokomafont{chapter}{}
but somehow this is not working with the MakeUppercase
makro.
My question would be if a similar command to \renewcommand*{\chapterformat}
exists where I can access a variable for the chaptertitle?
Best Answer
Second update
Here is a new and in my opinion better suggestion that needs KOMA-Script Version 3.19 or newer. In version 3.19 there is a new command
\chapterlineswithprefixformat
that could be redefined to use\MakeUppercase
for the chapter titles.Note: If you also want to use
\MakeUppercase
without the optionchapterprefix=true
you have to redefine the command\chapterlinesformat
:Update
My original answer (see below) works with both MiKTeX2.9 and TL 2015 but not with 2014 (but you can load
fixltx2e
to get it to work as @Johannes mentioned in a comment). So here is another suggestion.Note, you have to redefine
\tablename
,\listfigurename
,\listtablename
, ... so that they use\chaptertitleformat
and you have to insert this in all\chapter
commands. But as an advantage now there is only a switch in the\addtokomafont
command.Original answer (does not work with Version 3.19)
Here is a suggestion but note that
\MakeUppercase
inside\setkomafont
or\addtokomafont
can be problematic. In any case\MakeUppercase
have to be the last command added to the komafont of a fontelement because it needs an argument.