[Tex/LaTex] Headers and font in KOMA-script

koma-scriptscrlayer-scrpage

I am setting up the layout for my bachelor thesis using scrbook as basis for a self-made documentclass with twosided print. I want a header containing the current part number and name on the outer side (left on even pages, right on odd pages), the current chapter number and name on the center of the head and the same for section on the inner side. I found this example in the KOMA-Script documentation:

\usepackage{scrlayer-scrpage}
\pagestyle{scrheadings}
\automark[chapter]{chapter}
\automark*[section]{}

It puts the chapter on the outer side on even pages and the section on the outer side on odd pages. Sadly, I was not able to modify this to fit my needs because I do not really understand the way KOMA-Script works here. If a part starts but there is still no chapter in it, the place for the chapter shall remain empty (same for chapter and section). Can anyone help?

Furthermore, I would like to change all fonts that KOMA-Script changes (e.g. toc, section, chapter…) back to the default computer modern as I do not like the font KOMA-Script uses here. Is there a better way than changing all the fonts manually like this:

\addtokomafont{section}{\fontfamily{cmr}\selectfont}

Best Answer

For the part entries in the page header I will modify my example from scrpage2: Three “marks” for headings. Note that there must be no unstarred \automark command after the redefinition of \partmark because this would reset this definition.

To get serif font in the section titles you can change font element disposition

\setkomafont{disposition}{\normalcolor\bfseries}

or you can use the undocumented option

headings=standardclasses

If also font elements like descriptionlabel should use the serif font you can set the undocumented option egregdoesnotlikesansseriftitles which was a result of this question and needs KOMA version 3.20 or newer.

\documentclass[
  egregdoesnotlikesansseriftitles,% needs version 3.20 or newer
  %headings=standardclasses
]{scrbook}
%\providecommand*\Ifstr{\ifstr}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
%\providecommand*\Ifnumbered{\ifnumbered}% needed up to and including KOMA-Script version 3.27, see https://komascript.de/faq_deprecatedif
\usepackage{scrlayer-scrpage}% activates page style scrheadings automatically
\automark[section]{chapter}
\newmarks\currentpart

\renewcommand\partmark[1]{% after all unstarred \automark commands!
  \marks\currentpart{\Ifnumbered{part}{\partname~\thepart\autodot\enskip}{}#1}%
  \markboth{}{}%
  }
\newcommand\partinheadfoot{\firstmarks\currentpart}

\clearpairofpagestyles
\ohead{\partinheadfoot}
\chead{\leftmark}
\ihead{\Ifstr{\leftmark}{\rightmark}{}{\rightmark}}
\ofoot*{\pagemark}

\renewcommand\partpagestyle{empty}
\usepackage{lipsum}% for dummy text
\begin{document}
\tableofcontents
\part{First Test}
\chapter{A Chapter}
\section{A Section}
\lipsum

\part{Second Test}
\chapter{Only a Chapter}
\lipsum

\part{Third Test}
\section{Only a Section}
\lipsum

\part{Fourth Test}
\lipsum
\begin{description}
\item[Testlabel] Text
\end{description}
\end{document}

enter image description here

enter image description here

enter image description here

enter image description here

If your part, chapter or section titles are to long for the header, you can use option headings=optiontohead or headings=optiontoheadandtoc to use a short title in head and the long (or an other) version in TOC. See the explanations for \part[short version ]{heading etc. in the KOMA-Script documentation section "3.16. Structuring of Documents".

Related Question