Как использовать более одного цвета в правиле заголовка с помощью пакета fancyhdr

Как использовать более одного цвета в правиле заголовка с помощью пакета fancyhdr

Я хотел бы создать несколько headrules с более чем одним цветом внутри. Проблема в том, что я получаю следующее предупреждение в журнале:

предупреждение pdfTeX: pdflatex: вывести пустой стек цветных страниц 0

Вторая страница моего документа напечатана предпоследним использованным цветом для headrule. Другая проблема заключается в том, что rhead заполнен нежелательным значением на второй странице.

Я могу найти способ обработки (добавив \normalcolorперед каждым \colorв \renewcommand\headruleи добавив \rhead{}), но я боюсь получить некоторые другие проблемы, когда мой документ будет более полным (потому что ошибки все еще там, исправлен только вывод).

Я много искал по этому поводу, но ничего действительно полезного не нашел.

Как мне правильно управлять цветовой палитрой в этом случае?

Вот использованный код:

\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

Использование \colorнапрямую затруднительно, так как это изменит последовательные цвета глобально. Лучше использовать \begingroup...\endgroupпару вокруг \colorизменения, в данном случае, в переопределенной \headruleкоманде. Это убирает сообщение об ошибке и должно быть отказоустойчивым. Глобальный стек цветов для документа тогда не изменяется.

\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}

Связанный контент