Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

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.

share|improve this answer
    
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
add comment

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
    \patchcmd{\ps@headings}{\thepage\hfil}{\textcolor{red}{\thepage}\hfil}{}{}
    \patchcmd{\ps@headings}{\hfil\thepage}{\hfil\textcolor{red}{\thepage}}{}{}
\else
    \patchcmd{\ps@headings}{\hfil\thepage}{\hfil\textcolor{red}{\thepage}}{}{}
\fi
% patch the "myheadings" page style
\patchcmd{\ps@myheadings}{\thepage\hfil}{\textcolor{red}{\thepage}\hfil}{}{}
\patchcmd{\ps@myheadings}{\hfil\thepage}{\hfil\textcolor{red}{\thepage}}{}{}
\makeatother

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.