Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm new here, I have tried to solve most of the problems with my TEX code and so far I have been successful in solving all of them except for this one.

I would like to show the word "CONTENTS" in the header of the table of contents section in cyan.

Here is a minimal working example:

\documentclass[oneside,english]{book}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\usepackage{amsmath}
\usepackage{fancyhdr}
\usepackage{lipsum}
\usepackage{xcolor}

\pagestyle{fancy}
\fancyhead[LO,RE]{\thepage}

\renewcommand\contentsname{TABLE OF CONTENTS}

\makeatletter
%
\makeatother
%
\usepackage{babel}
\begin{document}
\tableofcontents{}
%
\chapter{ZXCVB}
\lipsum{}
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\chapter{ZXCVB}
\lipsum
%
\end{document}

In my actual code, I successfully changed a List of Symbols and a Bibliography parts by doing the following:

\chapter*{List of symbols}
\markboth{\textcolor[cmyk]{1,0,0,0}{List of symbols}}{}
\markright{\textcolor[cmyk]{1,0,0,0}{List of symbols}}{}

And

\renewcommand\bibsection{\chapter*{Bibliography}}
\markboth{\textcolor[cmyk]{1,0,0,0}{Bibliography}}{}
\markright{\textcolor[cmyk]{1,0,0,0}{Bibliography}}{}

But this doesn't seem to work on the Table of Contents.

Just a little bit of context: I'm using a custom class from my university, and somehow that class only colors the headers of the numbered chapters and sections, that's why I had to manually set the colors of the unnumbered sections.

Thanks in advance!

share|improve this question
    
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. –  Christian Hupfer Jun 17 at 15:56

2 Answers 2

I don't know about the class provided by your University, so this will apply to the book style, but hopefully also to your class.

To display the title "CONTENTS" in the header in cyan, I don't see any nicer way than doing some hack like redefining \markboth for when LaTeX will call it from within \tableofcontents. I would do something like this in the preamble:

\let\oldmarkboth\markboth
\newcommand\cyanmarkboth[2]{%
  \oldmarkboth{\textcolor[cmyk]{1,0,0,0}{#1}}{\textcolor[cmyk]{1,0,0,0}{#2}}%
}

And then, you can place the command

\let\markboth\cyanmarkboth

before the table of contents, or in general at any point before a chapter of the document for which you want the header to appear in cyan. This redefines the \markboth command to your custom \cyanmarkboth which adds the cyan color. If you later want to restore the original \markboth command, use

\let\markboth\oldmarkboth

Again, it might be that your class fiddles itself with \markboth already, in which case your definitions might interfere. Just hope for the best. (At some point, it might be instructive to inspect the source code of the class file if you're trying to tweak things.)

A separate issue which your code seems to have: you seem to want to display "Table of Contents" instead of "Contents", by using \renewcommand\contentsname{...}. This way clashes with the babel package; the solution to this is described here:

\addto\captionsenglish{%
  \renewcommand\contentsname{...}%
}
share|improve this answer
    
Thank you so much for your help! I used the hack and it worked. I would upvote your answer but I lack the reputation. As soon as I get more, you get upvoted :) –  elporsche Jun 19 at 18:56
    
you're welcome, glad this helped :) Don't worry about the upvote. In case this answer helped to solve your problem, you can consider also accepting it. Also, the possible downside of putting the cyan color command in the \contentsname itself is that the chapter title will also appear in cyan (but that depends of course on what you want). –  phfaist Jun 20 at 10:01

I tried phfaist's answer and it worked.

But for future record, I also happened to find a fast way of doing it:

In order to change the color of the Contents section, one can also do the following:

\renewcommand\contentsname{\textcolor[cmyk]{1,0,0,0}{Contents}}\tableofcontents

Apparently, I use the babel package and it did not clash with the \renewcommand\contentsname command; I checked my University's custom class, and the solution to the clashing posted by phfaist was already implemented.

Thank you!!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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