KOMA-Script: How to style the title of a chapter
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.
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}
A bit alternative approach:
\documentclass{scrreprt}
\let\raggedchapter\centering
\setkomafont{chapterprefix}{\normalsize\mdseries}
\KOMAoption{chapterprefix}{true}
\renewcommand{\chapterheadmidvskip}{%
\par\nobreak\vskip -.1cm {\rule{.9\textwidth}{.5pt}}\par%
}
\RedeclareSectionCommand[beforeskip=0pt,afterskip=8\baselineskip]{chapter}
\usepackage{xpatch}
\tracingpatches
\xpatchcmd{\@@makeschapterhead}{%for the unnumbered
\usekomafont{chapter}{#1}\par
}{%
\usekomafont{chapter}{\MakeUppercase{#1}}\par
}{}{}
\xpatchcmd{\@@makechapterhead}{%for numbered
\usekomafont{chapter}{#1}\par
}{%
\usekomafont{chapter}{\MakeUppercase{#1}}\par
}{}{}
\renewcommand*{\chapterformat}{%
\mbox{\MakeUppercase{\chapappifchapterprefix{\nobreakspace}}\thechapter\autodot
\IfUsePrefixLine{}{\enskip}}%
}
\begin{document}
\tableofcontents
\listoffigures
\chapter*{Bussy Baboon}
\chapter{walzing Wombat}
\end{document}