3

I would like to create some headrules with more than one color inside. The problem is that I get the following warning in the log :

pdfTeX warning: pdflatex: pop empty color page stack 0

The second page of my document is printed with the penultimate used color for the headrule. Another problem is that the rhead is populated with an undesirable value in the second page.

I can find a way to process (by adding \normalcolor before each \color in the \renewcommand\headrule and by adding \rhead{}), but i'm afraid to get some other problems when my document will be more complete(because the errors are still there, only the output is fixed).

I've done a lot of search about it, but nothing really helpfull.

How can I manage correctly the color stack in this case ?

Here is the used code:

\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{eso-pic}
\usepackage{xcolor}


\definecolor{logoColor}{RGB}{237,162,153}

\setlength\oddsidemargin{-0.5in}% marge de gauche (référence 0 est à 1 inche)
\setlength\topmargin{-0.75in}%espace blanc au dessus du header (référence 0 est à 1 inche)
\setlength\headheight{33pt}%see in a log, to avoid further problem in some cases
\setlength\headsep{1in}

\pagestyle{fancy}

\renewcommand\headrule{
  \color{logoColor}
  \vspace{1pt}
  \hrule height 2pt width\headwidth
  \vspace{1pt}
  \color{blue}
  \hrule height 1pt width\headwidth
}


\chead{ref:0214-07}

\begin{document}
This is some preamble text that you enter yourself.
\section{Text for the first section}
\lipsum[1]
\subsection{Text for a subsection of the first section}
\lipsum[2-3]
\part{test}
\subsection{Another subsection of the first section}
\lipsum[4-5]
\section{The second section}
\lipsum[6]
\subsection{Title of the first subsection of the second section}
\lipsum[7]
\end{document}
1

Using \color directly is tricky, as it will change the consecutive colors globally. It's better to use a \begingroup...\endgroup pair around a \color change, in this case, within the redefined \headrule command. This removes the error message and should be failsafe. The global color stack for the document is not changed then.

\documentclass{article}
\usepackage{geometry}
\usepackage{fancyhdr}
\usepackage{amsmath ,amsthm ,amssymb}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{eso-pic}
\usepackage{xcolor}


\definecolor{logoColor}{RGB}{237,162,153}

\setlength\oddsidemargin{-0.5in}% marge de gauche (référence 0 est à 1 inche)
\setlength\topmargin{-0.75in}%espace blanc au dessus du header (référence 0 est à 1 inche)
\setlength\headheight{33pt}%see in a log, to avoid further problem in some cases
\setlength\headsep{1in}

\pagestyle{fancy}

\renewcommand\headrule{%
  \begingroup
  \color{logoColor}
  \vspace{1pt}
  \hrule height 2pt width\headwidth
  \vspace{1pt}
  \color{blue}
  \hrule height 1pt width\headwidth
  \endgroup
}



\chead{ref:0214-07}

\begin{document}
This is some preamble text that you enter yourself.
\section{Text for the first section}
\lipsum[1]
\subsection{Text for a subsection of the first section}
\lipsum[2-3]
\part{test}
\subsection{Another subsection of the first section}
\lipsum[4-5]
\section{The second section}
\lipsum[6]
\subsection{Title of the first subsection of the second section}
\lipsum[7]
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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