[Tex/LaTex] How to set the color of page number

colorheader-footer

I am using white colored font on black page and somehow I am losing my page numbers. I suppose the page number is still in black color. So How do we set the color of page number? And while on the topic, how about color of page runners etc.

Best Answer

You can add all the colour information into your page style using fancyhdr.

In the following MWE, I've defined mypagestyle to set the page number in red (using \textcolor{red}{\thepage}) and modified the header rule macro \headrule:

enter image description here

\documentclass{article}
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{fancyhdr}% http://ctan.org/pkg/fancyhdr
\makeatletter
\fancypagestyle{mypagestyle}{%
  \fancyhf{}% Clear header/footer
  \fancyfoot[C]{\textcolor{red}{\thepage}}% Page # in middle/centre of footer
  \renewcommand{\headrulewidth}{.4pt}% .4pt header rule
  \def\headrule{{\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
    \color{red}\hrule\@height\headrulewidth\@width\headwidth \vskip-\headrulewidth}}
  \renewcommand{\footrulewidth}{0pt}% No footer rule
%  \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
%    \vskip-\footruleskip\vskip-\footrulewidth
%    \hrule\@width\headwidth\@height\footrulewidth\vskip\footruleskip}}
}
\makeatother
\pagestyle{mypagestyle}
\begin{document}
\lipsum
\end{document}

The same would hold if you're interested in having a coloured footer rule. I've included the \footrule definition in comment, for completeness.

Related Question