手动自定义标题颜色

手动自定义标题颜色

我想更改页面的背景颜色,也必须更改文本颜色。虽然这对于正文来说没有问题,但页眉(和页脚)文本颜色需要单独更改。请考虑这个简单但不适用的示例:

\documentclass{report}
\usepackage{xcolor}
\begin{document}
A black and white page.
\newpage
\pagecolor{green}
%%%%%%%%
{\color{white}%
\chapter*{A white and green page}
}
%%%%%%%%
\thispagestyle{myheadings}
\makeatletter
\global\let\originaloddhead\@oddhead
\global\let\originalevenhead\@evenhead
\renewcommand{\@oddhead}{{\protect\color{white}\originaloddhead}}
\renewcommand{\@evenhead}{{\protect\color{white}\originalevenhead}}
\makeatother
\markboth{header text}{header text}
%%%%%%%%
{\color{white}%
Some text.
}
%%%%%%%%
\newpage
\nopagecolor
\makeatletter
\let\@oddhead\originaloddhead
\let\@evenhead\originalevenhead
\makeatother
Another black and white page.
\end{document}

不起作用但给出了黑色标题。

工作是什么

\documentclass{report}
\usepackage{xcolor}
\makeatletter
\newcommand{\ps@inverted}{%
  \renewcommand{\@oddhead}{%
    {\protect\color{white}\small\upshape\hfil\rightmark\hskip\tw@ em\thepage}}%
  \renewcommand{\@evenhead}{%
    {\protect\color{white}\small\upshape\thepage\hskip\tw@ em\leftmark\hfill}}%
 }
\makeatother

\begin{document}
A black and white page.
\newpage
\pagecolor{black}%
{\color{white}%
\chapter*{A white and black page}
\thispagestyle{myheadings}
\markboth{header text}{header text}
\thispagestyle{inverted}%
Some text.
}
\newpage
\thispagestyle{myheadings}
\nopagecolor
Another black and white page.
\end{document}

但我想知道为什么 第一次尝试没有成功,可能还有解决办法。好的,花式高清nccfancyhdr或者类似的软件包可能会解决问题,但我不只是想要一个解决方案(我有一个,见上文),而是要理解如何工作

答案1

您有一个{组从 开始,\color{white}该组在页面末尾结束。它保持颜色变化局部,但您的 定义\originaloddhead 在组末尾被丢弃。您需要

\global\let\originaloddhead\@oddhead
\global\let\originalevenhead\@evenhead

相关内容