# Different pagestyles for different chapters

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}
\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?

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}
\clearpairofpagestyles
\chead*{\currentpagestyle}% show the used page style

\newpairofpagestyles
{StyleA}% name of the new layer page style
{
\ohead*{StyleA outer head}% note the *: same content for plain.StyleA and StyleA
}% definitions for the new page style
\newpairofpagestyles
{StyleB}
{
}

\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:

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.