# Manually customizing a header's colour

I would like to change the background colour of a page and necessarily also the text colour. While that is no problem for the main text, the header (and footer) text colour needs to be changes separately. Consider this minimal-but not working-example:

\documentclass{report}
\usepackage{xcolor}
\begin{document}
A black and white page.
\newpage
\pagecolor{green}
%%%%%%%%
{\color{white}%
\chapter*{A white and green page}
}
%%%%%%%%
\makeatletter
\makeatother
%%%%%%%%
{\color{white}%
Some text.
}
%%%%%%%%
\newpage
\nopagecolor
\makeatletter
\makeatother
Another black and white page.
\end{document}


does not work but gives a black header.

What does work is

\documentclass{report}
\usepackage{xcolor}
\makeatletter
\newcommand{\ps@inverted}{%
{\protect\color{white}\small\upshape\hfil\rightmark\hskip\tw@ em\thepage}}%
{\protect\color{white}\small\upshape\thepage\hskip\tw@ em\leftmark\hfill}}%
}
\makeatother

\begin{document}
A black and white page.
\newpage
\pagecolor{black}%
{\color{white}%
\chapter*{A white and black page}
\thispagestyle{inverted}%
Some text.
}
\newpage
\nopagecolor
Another black and white page.
\end{document}


but I would like to know why the first attempt does not work and possibly how to fix it. OK, fancyhdr, nccfancyhdr or similar packages would probably do the trick, but I don't just want a solution (I got one, see above), but to understand how things work.

-

You have a { group starting just before the \color{white} which finishes at the end of the page. It keeps the colour change local but also your definition of \originaloddhead is discarded at the end of the group. You would need
\global\let\originaloddhead\@oddhead

move the \newpage up a line so the previous page is output within the scope not just after it. You can get away with this as you have forced page breaks, in general what you should do is define a new page style which is like the old one but with coloured header then use \thispagestyle{colouredhead} and latex will take care if using the right header on the right page. –  David Carlisle Jun 20 '12 at 9:31
OK, moving the \newpage into the group makes sense, but when I tested this, it had no effect (header still black). To make things easier I limited the text white just to the text, but that does not work either. As you can see from the second (working) example, I defined a new pagestyle, and that indeed works. For just 1 single page with header, \chapter* and 2 lines of text this is probably overkill, but I'm using that. I'm just curious why the other approach did not work. When I make a mistake here, I'll probably also make it somewhere else. (And I'd like to understand how things work.) –  Stephen Jun 20 '12 at 10:12