页眉中的目录和参考书目的文本颜色,

页眉中的目录和参考书目的文本颜色,

感谢你的存在。有了这里的解决方案,事情会变得更容易。但有时这还不够(对我来说)。

我正在使用经过修改的书籍类。使用以下命令更改页眉的颜色。

\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}

这对目录和参考书目不起作用。另外,以下内容似乎没有效果

\newcommand*\setheader[1]{\markboth{\color{title}#1}{\color{title}#1}}

所以问题是:目录和参考文献的命令是什么?

提前感谢一切!如果我没有仔细搜索,我已经很抱歉了。干杯,罗伯特

这是一些代码。它不是真正精简的,也不是很好,但它确实有用。

\documentclass{book}
\usepackage{lipsum}
\RequirePackage[english]{babel}
\RequirePackage{chapterbib}
\RequirePackage{fancyhdr}
\RequirePackage{titletoc}
\RequirePackage{xcolor}   

%% The style for titles is small caps.
\def\titlefont{\rmfamily}
\def\titleshape{\scshape}
\def\titlestyle{\titlefont\titleshape\bfseries}
\def\headerstyle{\titlefont\titleshape\bfseries}

%% colors
\definecolor{tudelft-cyan}{cmyk}{1,0,0,0}
\colorlet{title}{tudelft-cyan}

%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
    %% Page numbers on the top left and top right.
    \fancyhead[LE]{\titlefont\thepage}
    \fancyhead[RO]{\titlefont\thepage}
    %% Chapter name on the left (even) page.
    \fancyhead[RE]{\titlefont\titleshape\nouppercase{\leftmark}}
    %% Section name on the right (odd) page.
    \fancyhead[LO]{\titlefont\titleshape\nouppercase{\rightmark}}
}

%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}

%% Print the current chapter and section at the top of the page in cyan.
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \color{title}#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \color{title}#1}}

%% The setheader command can be used to print the title of unnumbered chapters in the page header.
\newcommand*\setheader[1]{\markboth{\color{title}#1}{\color{title}#1}}


\begin{document}

\tableofcontents

\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\lipsum
\lipsum
\lipsum[1-2]
\begin{thebibliography}{}
\end{thebibliography}

\chapter{Chapter}
\section{Section}
\subsection{Subsection}
\lipsum

\end{document}

答案1

正如评论中提到的,您必须使用 package 修补原始类命令etoolbox。可以以类似的方式对图表和表格列表以及索引进行路径规划。我定义了一个辅助宏,现在所有与标题有关的元素都共享该宏。通过在一个集中位置定义颜色,可以更轻松地更改外观。

请注意,如果你想要一个万无一失的类,编写自己的类可能会非常复杂且耗时。现在你的代码是做好工作(正如您自己所说),但它不是很漂亮。请考虑使用文件dtx以更详细的内容注释您的代码,然后精简代码,为您提供一个漂亮而干净的cls文件。

另一个提示是,看看 KOMA 类。它们比标准类和 proide 命令有所改进,例如 \addchap制作一个包含目录条目的未编号章节、设置页眉以及执行作者可能会忘记的一些小操作,以保持文档更加一致。

无论哪种方式,您都应该使用辅助宏,就像我所做的那样 titlecolor

我建议不要使用 chapterbib ,而要使用现代且灵活的biblatex

\documentclass{book}
\RequirePackage[english]{babel}
\RequirePackage{chapterbib}
\RequirePackage{xspace}
\RequirePackage{fancyhdr}
\RequirePackage{titletoc}
\RequirePackage{xcolor}   

%% The style for titles is small caps.
\def\titlefont{\rmfamily}
\def\titleshape{\scshape}
%\def\titleshape{\scshape\color{title}}%Deciding to have the whole thing
%colored would be much easier
\def\titlestyle{\titlefont\titleshape\bfseries}
\def\headerstyle{\titlefont\titleshape\bfseries}

% colors
\definecolor{tudelft-cyan}{cmyk}{1,0,0,0}
\colorlet{title}{tudelft-cyan}

%% Fancy style for the main matter.
\fancypagestyle{mainmatter}{%
\fancyhf{}
    %% Page numbers on the top left and top right.
    \fancyhead[LE]{\titlefont\thepage}
    \fancyhead[RO]{\titlefont\thepage}
    %% Chapter name on the left (even) page.
    \fancyhead[RE]{\titlefont\titleshape\nouppercase{\leftmark}}
    %% Section name on the right (odd) page.
    \fancyhead[LO]{\titlefont\titleshape\nouppercase{\rightmark}}
}

%% The mainmatter style is default for normal pages.
\pagestyle{mainmatter}

\newcommand{\titlecolor}{\color{title}}
\renewcommand*\chaptermark[1]{\markboth{\thechapter.\ \titlecolor#1}{}}
\renewcommand*\sectionmark[1]{\markright{\thesection.\ \titlecolor#1}}
\newcommand*\setheader[1]{\markboth{\titlecolor#1}{\titlecolor#1}}
%Now all share the same helper macro `titlecolor` making it easier to maintain. 

\usepackage{blindtext}
\usepackage{etoolbox}
\patchcmd{\tableofcontents}{%
    {\MakeUppercase\contentsname}{\MakeUppercase\contentsname}%
}{
{\titlecolor\MakeUppercase\contentsname}{\titlecolor\MakeUppercase\contentsname}%
}
{}{}

\patchcmd{\thebibliography}{%
    {\MakeUppercase\bibname}{\MakeUppercase\bibname}%
}{
{\titlecolor\MakeUppercase\bibname}{\titlecolor\MakeUppercase\bibname}%
}
{}{}

\usepackage{pgffor}
\begin{document}

\tableofcontents

\foreach \n in {1,...,12} \blinddocument;
\cite{aristotle:physics}
\bibliographystyle{plain}
\bibliography{biblatex-examples}
\cleardoublepage\null

\end{document}

相关内容