1

I found this great example in an answer of this question How to use custom page style on a single page and another for all subsequent pages? and changed it a little bit.

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}
\newpagestyle{StyleA}{{StyleA left page}{StyleA right page}{Style A onesided document}}{{}{}{}}
\newpagestyle{StyleB}{{StyleB left page}{StyleB right page}{Style A onesided document}}{{}{}{}}
\usepackage{lipsum}

\begin{document}
\pagestyle{StyleB}% use StyeleB for the document
\chapter{chapter 1}
\lipsum[1-15]
\chapter{chapter 2}
\pagestyle{StyleA}% use StyleA only for this page
\cleardoublepage
\chapter{special chapter}
\lipsum[16-30]
\pagestyle{StyleB}% use StyleB for the document
\cleardoublepage
\chapter{Kapitel 3}
\lipsum[1-15]
\end{document}

This works quite good for me since I only want to change the headers for my chapters.

But there are some questions I could not find an answer to so I ask them here.

  1. How can I define the left, center and right part of the header or footer? I normally use \ohead{}, \chead{}, \ihead{}, etc.
  2. Is it possible to add these created styles so that they also will be used for the first page of the chapter? Using \chapterpagestyle{StyleA} is not working.
  3. I have created my own section command with \DeclareNewSectionCommand{}. Is it possible to automate it in a way, that the \pagestyle{StyleB}-command is added automatically to the normal chapter-command \chapter{}, so that the usage of it resets the changed pagestyle to StyleB?
3

If you want to use \ohead etc. to define the parts of header and footer, then use \newpairofpagestyles for the definition of your new page styles. Then you get pairs of pagestyles, eg. StyleA as main pagestyle and plain.StyleA as associated plain style.

Note that plain is only an alias for the plain style of the active "pair of pagestyles".

\documentclass{scrbook}
\usepackage{scrlayer-scrpage}% sets pagestyle scrheadings automatically
\clearpairofpagestyles
\cfoot*{\pagemark}% note the *: same content for plain.scrheadings and scrheadings
\chead*{\currentpagestyle}% show the used page style

\newpairofpagestyles
  [scrheadings]% scrheadings as parent style -> clone its *current* settings
  {StyleA}% name of the new layer page style
  {
    \ohead*{StyleA outer head}% note the *: same content for plain.StyleA and StyleA
    \ihead*{StyleA inner head}%
  }% definitions for the new page style
\newpairofpagestyles
  [scrheadings]
  {StyleB}
  {
    \ohead{StyleB outer head}%
    \ihead{StyleB inner head}%
  }

\usepackage{xpatch}
\xpretocmd\chapter{\cleardoublepage\pagestyle{StyleB}}{}{\PatchFailed}% reset the page style for \chapter

\usepackage{lipsum}% only for dummy text
\begin{document}
\pagestyle{StyleB}
\tableofcontents
\clearpage Test
\chapter{chapter 1}
\chapter{chapter 2}
\chapter{special chapter}
\pagestyle{StyleA}
\lipsum[16-30]
\chapter{Kapitel 3}
\lipsum[1-15]
\end{document}

Result:

enter image description here

enter image description here

Additional remark: By default the style of chapter pages is plain. This can be changed by redefinition of \chapterpagestyle: \renewcommand{\chapterpagestyle}{<page style name>}. But in the example above there was no redefinition needed because \pagestyle{StyleA} yields to plain as alias of plain.StyleA and \pagestyle{StyleB} yields to plain as alias of plain.StyleB.

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.