2

thank you for existing. Things are easier with solutions from here. But sometimes it is not enough (for me).

I'm using a modified book class. The page header are changed in color with the following command.

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

This does not work for the table of contents and the bibliography. Also the following seems not to have an effect

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

So the question is: what is the command for the toc and the references?

Thanks for everything in advance! If I haven't searched properly enough I'm already sorry.Cheers, Robert

Here is some code. It's not real minimal and not nice, but it does the trick.

\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}
Bohlero
  • 21
  • Hi and welcome, by default toc/lof/lot etc set the headers via markboth (or another low level command). You need to patch those using package etoolbox. We can't know right now, if your modified class alters the definition, so there can't be a definiitive answer right now. But we can speculate and demonstrate using the default. – Johannes_B Oct 23 '14 at 16:30
  • Can you give us some code, best in form of a minimal working example, so have a base to work with and play around? – Johannes_B Oct 23 '14 at 16:40
  • Initially I was hoping it is just a missing command. But the etoolbox exceed my Latex knowledge. I was trying to fool around with the fancyhdr, but did not achieve anything. – Bohlero Oct 24 '14 at 09:49

1 Answers1

2

As mentioned in the comments, you have to patch the original class commands using package etoolbox. Pathcing the list of figures and tables and the index can be done in a similar way. I defined a helper macro which is now shared by all elements having something to do with the header. This makes it much more easy to change the appearance by having the color in one centralized location defined.

Please be aware that writing up an own class can be very complicated and time consuming if you want it to be bulletproof. Right now your code is doing the job (as you said yourself), but it isn't very pretty. Please consider to use a dtx file to comment your code in a more verbose matter and later strip down the code, giving you a nice and clean cls file.

Another tipp, have a look at the KOMA-classes. They are improvements over the standard classes and proide command like \addchap making an unnumbered chapter including a TOC-entry, setting the header and doing some minor stuff an author might forget keeping the document more consistent.

Either way, you should work with helper macros as i did with titlecolor.

Instead of chapterbib i would suggest to use the modern and flexible 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}
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • Thank you, very...sexy. Works! I'll have a look into the other suggestions, too. But as usual: who has the time to actually learn Latex? It is the results what one wants, not the way to go there. – Bohlero Oct 24 '14 at 15:33
  • @Bohlero: ... and who has time to write textbooks, or anything? there have to be people "in the back room", running the archives, managing miktex and tex live, and learning (la)tex (and context) well enough to be able to help others; and in another part of the universe, there are people developing latex & context, as well as all of the packages. i learned latex to lead a documentation project (in the '90s); others learned it for fun, but either way, someone has to do it. – wasteofspace Oct 24 '14 at 17:06
  • @wasteofspace I am facing support questions everyday based on bad classes and templates done by people thinking they have the knowledge to do it. Templates are a constant source of misunderstading and annoyance to supporters. So please bohlero, invest some time in doing it properly, if you want to share it with others. – Johannes_B Oct 24 '14 at 19:51
  • @Bohlero This is just an advice tough, i can't force you to do anything. – Johannes_B Oct 24 '14 at 19:52
  • Hello after digging a bit more I finally understood better how this works. The suggestion to have the whole header coloured would differs in the way that the numbers of chapters or sections should actually stay black. Using etoolbox worked for the TOC but not for the bibliography when not using the "thebibliography" as in my bad example further up. The package titletoc (actually not bad!) overwrites the \contentsname, so that I finally used \renewcommand{\tocetcmark}[1]{\@mkboth{\color{title}\MakeUppercase{#1}}{\color{title}\MakeUppercase{#1}}} to solve it for the bibliography. – Bohlero Nov 17 '14 at 13:28
  • @Bohlero Why aren't you using \titlecolor to work in a consistent way? You are developing a class, you should work concentrated ;-) – Johannes_B Nov 17 '14 at 13:45
  • tocetcmark seems to be defined with package tocbibind. This package takes control over all the list stuff; contens, figures, tables and the bib-stuff and redefines the LaTeX base macros. The above solution cannot work when using package tocbibind. They won't work with KOMA as well. – Johannes_B Nov 17 '14 at 13:58