[Tex/LaTex] KOMA-Script: How to style the title of a chapter

chapterskoma-scriptsectioning

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.

\documentclass[english]{scrreprt}[2015/09/29]% needs version 3.19 or newer
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}

\KOMAoption{chapterprefix}{true}
\renewcommand*\raggedchapter{\centering}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=8\baselineskip]{chapter}
\setkomafont{chapterprefix}{\normalsize\mdseries}

\renewcommand*{\chapterformat}{%
  \chapappifchapterprefix{\nobreakspace}\thechapter\autodot%
  \IfUsePrefixLine{%
    \par\nobreak\vspace{-\parskip}\vspace{-.6\baselineskip}%
    \rule{0.9\textwidth}{.5pt}%
  }{\enskip}%
}

\renewcommand\chapterlineswithprefixformat[3]{%
  \MakeUppercase{#2#3}
}

\begin{document}
\tableofcontents
\chapter{Chapter One}
\textbf{\KOMAScriptVersion}
\par
\Blindtext
\addchap{Chapter without number}
\Blindtext
\end{document}

Note: If you also want to use \MakeUppercase without the option chapterprefix=true you have to redefine the command \chapterlinesformat:

\makeatletter
\renewcommand{\chapterlinesformat}[3]{%
  \@hangfrom{#2}{\MakeUppercase{#3}}%
}
\makeatother

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.

\documentclass[english]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}

\KOMAoption{chapterprefix}{true}
\renewcommand*\raggedchapter{\centering}
\newif\ifmakeupper
\newcommand*\chaptertitleformat[1]{\ifmakeupper\MakeUppercase{#1}\else#1\fi}
\addtokomafont{chapter}{\makeuppertrue}
\setkomafont{chapterprefix}{\normalsize\mdseries}
\renewcommand*{\chapterformat}{%
    \MakeUppercase{\chapappifchapterprefix{\nobreakspace}}\thechapter\autodot%
    \IfUsePrefixLine{%
      \par\nobreak\vspace{-\parskip}\vspace{-.6\baselineskip}%
      \rule{0.9\textwidth}{.5pt}%
    }{\enskip}%
}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=8\baselineskip]{chapter}

\renewcaptionname{english}{\contentsname}{\chaptertitleformat{Contents}}

\begin{document}
\tableofcontents
\chapter{\chaptertitleformat{Chapter One}}
\textbf{\KOMAScriptVersion}
\par
\Blindtext
\addchap{\chaptertitleformat{Chapter without number}}
\Blindtext
\end{document}

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.

enter image description here


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.

\documentclass[english]{scrreprt}[2015/02/07]
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{blindtext}

\KOMAoption{chapterprefix}{true}
\renewcommand*\raggedchapter{\centering}
\addtokomafont{chapter}{\MakeUppercase}
\setkomafont{chapterprefix}{\normalsize\mdseries}
\renewcommand*{\chapterformat}{%
    \chapapp~\thechapter%
    \par\nobreak\vspace{-\parskip}\vspace{-.6\baselineskip}%
    \rule{0.9\textwidth}{.5pt}%
}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=8\baselineskip]{chapter}

\begin{document}
\tableofcontents
\blinddocument
\end{document}

enter image description here