10

I'm trying to reduce the number of packages I'm loading in my documents and I read on the KOMA documentation (and elsewhere) that it can define page styles better than fancyhdr. But each time I try to set up scrpage2 I get weird results, such as with the wrong section titles or positioning of elements. How can I rewrite my fancyhdr layout to scrpage2?

\usepackage{fancyhdr}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}

\pagestyle{fancy}
\fancyhf{}
\fancyhead[LO]{\textit{\nouppercase{\scshape \mytitle{}}}}
\fancyhead[RE]{\textit{\nouppercase{\scshape \thechapter. \leftmark{}}}}
\fancyfoot[CE,CO]{\thepage{}}

\fancypagestyle{plain}{
  \fancyhf{}
  \fancyfoot[CE,CO]{\thepage{}}
}

\fancypagestyle{preface}{
  \fancyhf{}
  \fancyhead[RE]{\textit{\nouppercase{\scshape \leftmark{}}}}
  \fancyhead[LO]{\textit{\nouppercase{\scshape \mytitle{}}}}
  \fancyfoot[CE,CO]{\thepage{}}
}

The preface style is used for the pages before Chapter 1; other pages just use the default fancy style.

8

Here's a scrpage2 solution that should at least come close to what you want. Some remarks:

  • No head- and footrules is the default setting of scrpage2.
  • Disabling uppercase letters in the header is done by the package option nouppercase.
  • The optional arguments of \lohead, \rehead and \cfoot control the settings for the scrplain pagestyle (which replaces plain).
  • The heading font is controlled by the \headfont macro.

I didn't emulate your separate preface pagestyle (which differs only slightly from your fancy style). Instead, I redefined \chaptermarkformat (which is able to differentiate between numbered and unnumbered chapters).

\documentclass{scrbook}

\usepackage[automark,nouppercase]{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot
\lohead[]{(mytitle)}% Placeholder for \mytitle
\rehead[]{\leftmark}
\cfoot[\pagemark]{\pagemark}
\renewcommand*{\headfont}{\itshape\scshape}% Will equal \scshape for most fonts
\renewcommand*{\chaptermarkformat}{\chapapp~\thechapter\autodot\enskip}

\usepackage{blindtext}

\begin{document}

\setcounter{secnumdepth}{-1}% Unnumbered chapters

\blinddocument

\setcounter{secnumdepth}{2}% Numbered chapters, sections, and subsections

\blinddocument

\end{document}

(The blindtext package is only used to add some dummy text to the example.)

  • With scrbook generally you do not need nouppercase, because the KOMA-Script classes do not use \MakeUppercase. – Schweinebacke Mar 7 '17 at 11:31
  • 2
    scrpage2 is obsolete. You can simply replace it by scrlayer-scrpage. You should then also replace \clearscrheadfoot by \clearpairofpagestyles and you can remove \pagestyle{scrheadings}. Instead of re-defining \headfont you should use \setkomafont{pageheadfoot}{…}. – Schweinebacke Mar 7 '17 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.