[Tex/LaTex] Replacing fancyhdr with scrpage2

fancyhdrheader-footerkoma-scriptscrpage2

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.

Best Answer

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.)