# \pagestyle does not work as expected

I'm using the fancyhdr package and I have defined headers & footers for the fancy page style using the fancypagestyle command. I have also defined a new page style, tocstyle, using the same command.

Defined in this order:

\pagestyle{fancy}{%
\def\footnotelayout{\color{darkgrey}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} % To change from all CAPS
\renewcommand{\sectionmark}[1]{\markright{#1}{}} % to normal case
\fancyhf{}
\fancyfoot[RE]{\footnotesize{\thepage\ \textsl{of} \pageref{LastPage}}}
\fancyfoot[LO]{\footnotesize{\thepage\ \textsl{of} \pageref{LastPage}}}
}

\fancypagestyle{tocstyle}{%
\fancyhf{}
\fancyfoot[RE]{\footnotesize{\thepage}}
\fancyfoot[LO]{\footnotesize{\thepage}}
}


In the main .tex file I use the tocstyle for the ToC and then I change to fancy, but instead of applying the fancy style it looks like it has the empty style, the pages are completely empty.

\documentclass[a4paper,11pt,titlepage,twoside,parskip=half-,bibliography=totoc]{scrreprt}
\begin{document}
\pagestyle{tocstyle}
\tableofcontents
\clearpage
\pagestyle{fancy}

\include{baForeword}
\include{bIntroduction}
...
\end{document}

-

The error is in

\pagestyle{fancy}{<your settings>}


The \pagestyle command requires only one argument, so the following text in braces is actually executed in a group and everything disappears after the closing brace.

\def\footnotelayout{\color{darkgrey}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}} % To change from all CAPS
\renewcommand{\sectionmark}[1]{\markright{#1}{}} % to normal case

\fancypagestyle{bookstyle}{
\fancyhf{}
\fancyfoot[RE]{\footnotesize{\thepage\ \textsl{of} \pageref{LastPage}}}
\fancyfoot[LO]{\footnotesize{\thepage\ \textsl{of} \pageref{LastPage}}}
}
\fancypagestyle{tocstyle}{%
\fancyhf{}
\fancyfoot[RE]{\footnotesize{\thepage}}
\fancyfoot[LO]{\footnotesize{\thepage}}
}


If you need to use the tocstyle page style for the table of contents, write something like

\begin{document}
\frontmatter
...
\pagestyle{tocstyle}
\tableofcontents
\listoffigures
%\cleardoublepage

\mainmatter
\pagestyle{bookstyle}

...


The \cleardoublepage should be added in order to mark precisely the transition between page styles; however, if \mainmatter immediately follows the table of contents pages, it's not necessary, because \mainmatter issues \cleardoublepage automatically.

It's better to define all the page styles necessary for the document, if one of them has to be used for more than one page (with \thispagestyle).

-
Unfortunately that didn't solve the problem. Now the tocstyle is applied to the whole document... –  benregn May 14 '11 at 13:45
@benregn: If you declare \pagestyle{tocstyle} somewhere, this declaration has its effect until countermanded by another \pagestyle declaration or, if given in a group, until the group ends. I'll update my answer. –  egreg May 14 '11 at 17:04