# How to set the color of page number

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.

-

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:

\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}{%
\fancyfoot[C]{\textcolor{red}{\thepage}}% Page # in middle/centre of footer
\renewcommand{\footrulewidth}{0pt}% No footer rule
%  \def\footrule{{\if@fancyplain\let\footrulewidth\plainfootrulewidth\fi
%    \vskip-\footruleskip\vskip-\footrulewidth
}
\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.

-
Thanks. How does the running title (short title) get to be treated? – Maesumi Jul 12 '12 at 22:22
@Maesumi: In the standard document class (like article), you could use \fancyhead[R]{\leftmark} to place \leftmark (sectional heading) in the Right header. – Werner Jul 12 '12 at 22:30
@Werner In my applied case, this answer seem to only solve the problem for some page-numberings, it seems (i.e. in \documentclass{book}, not in \documentclass{report}). It only works for those which are not shifted to the top of the page (sorry for not being able to use a technical term which demonstrates deeper understanding); it does e.g. not work for page numbers at the first page of a \part{...}. – Vincent Verheyen Apr 20 at 4:42
@VincentVerheyen: That's true since book and report issue \thispagestyle{plain} on first pages for their \chapters. This is a common scenario, and you'll have to (re)define the plain page style to cover those cases. – Werner Apr 20 at 22:34

If all you need to achieve is to change the color of the page numerals on a page, and if you can get by with using LaTeX's "plain" page style, the following MWE will show you how to do it.

\documentclass{article}
\usepackage{lipsum,xcolor,etoolbox} % lipsum for filler text
\makeatletter % change only the display of \thepage, but not \thepage itself:
\patchcmd{\ps@plain}{\thepage}{\textcolor{red}{\thepage}}{}{}
\makeatother
\begin{document}
\pagestyle{plain} % after changing a pagestyle command, it's necessary to invoke it explicitly
\lipsum[1-3]
\end{document}


In addition to the "plain" page style, the standard LaTeX document classes also provide the "headings" and "myheadings" page styles. If you're using one of these page styles and wish to reset the color of the page numerals, you should insert the following code in your document's preamble (in addition to loading the etoolbox and xcolor packages, of course):

\makeatletter
% patch the "plain" page style
\patchcmd{\ps@plain}{\thepage}{\textcolor{red}{\thepage}}{}{}
% patch the "headings" page style
\if@twoside

Then, be sure to issue either \pagestyle{plain}, \pagestyle{headings}, or \pagestyle{myheadings} after \begin{document}.