# Change the color of the header line

The answer to the question fancyhdr - Change horizontal line color on top of footer is not completely satisfactory, because it changes the position of the header line, for example with this example.

\documentclass{article}

\usepackage{xcolor}
\usepackage{fancyhdr}
\pagestyle{fancy}

\begin{document}
hello
\end{document}


Is it possible to change only the color of the line, without changing its position?

• A simple \renewcommand{\headrule}{{\color{red}\rule{\textwidth}{0.5pt}}} should do the trick. – Bernard Mar 14 at 18:33
• Thanks, but it does not (at least not on my computer). – Rastapopoulos Mar 14 at 18:34
• The position of the line isn't changed, neither with your code nor with mine. How is it modified, precisely? – Bernard Mar 14 at 19:15

Below I save the original \headrule in \oldheadrule, and then prepend \color{<colour>} to a newly-defined \headrule that just calls \oldheadrule. The approach is similar to etoolbox's \pretocmd.

\documentclass{article}

\usepackage{fancyhdr,xcolor}


• Thank you very much! I had tried exactly this, but with \newcommand{\oldheadrule}{\headrule}, which resulted in an infinite loop. – Rastapopoulos Mar 14 at 19:19