# Change color of a type of text like header/footer

Can we change the color of a logical type of text, say every header or every footer, by a single command? Header and footer is using fancyhdr.

I believe it should be a \renewcommand but won't it affect dependent packages like fancyhdr? I could define newer macros from the one which fancyhdr uses like \rfoot or \cfoot, to say \rfootcolored or \cfootcolored. But then I have to redesign the entire header/footer from scratch...which I don't want to do..

A MWE..

\documentclass{book}

\usepackage{lipsum}
\usepackage{fancyhdr}

\begin{document}
\pagestyle{fancy}

\chapter{Lipsum}
\lipsum[1-6]

\section{lipsumsection}
\lipsum[7-10]

\chapter{Lipsum2}
\lipsum[2-7]

\end{document}

-
Short answer: Yes. Long answer: But how to do it will depend on which part you want to modify. – Seamus Jun 25 '12 at 10:56
okay..i will edit my question then... – Vineet Menon Jun 25 '12 at 12:07
@VineetMenon: You should also include information on how you generate your headers and footers, by posting a minimal example. Otherwise someone might try to answer explaining how to do it with fancyhdr, and then you might answer "Actually, I'm using memoir, and this approach isn't working". You should always try to make questions as concrete and detailed as possible. – Jake Jun 25 '12 at 12:40
Probably an ifelse statement would be the simplest way here. – azetina Jun 25 '12 at 14:30
@VineetMenon: I think it would really help if you composed a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages. This will also serve as a test case and ensure that the solution actually works for you. – Peter Grill Jun 26 '12 at 5:13

You may use the etoolbox package to patch the internal fancyhdr macros \@fancyhead and \@fancyfoot (and in case you want colored rules, also \headrule and \footrule):

\documentclass{book}

\usepackage{lipsum}
\usepackage{fancyhdr}
\usepackage{xcolor}

\usepackage{etoolbox}

\makeatletter
\patchcmd{\@fancyfoot}{\rlap}{\color{green}\rlap}{}{}
\patchcmd{\footrule}{\hrule}{\color{green}\hrule}{}{}
\makeatother

\begin{document}
\pagestyle{fancy}

\chapter{Lipsum}
\lipsum[1-6]

\section{lipsumsection}
\lipsum[7-10]

\chapter{Lipsum2}
\lipsum[2-7]

\end{document}


-