Text FormattingColor the contents word

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
Tolaso
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

Color the contents word

Post by Tolaso »

I have the tables of contents rendered in DarkRed using the commands

Code: Select all

\usepackage{xcolor}
\definecolor{DarkRed}{RGB}{139,0,0}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}
and everything goes well ... Take a look
preview.png
preview.png (109.58 KiB) Viewed 11344 times
For aesthetic reasons I'd like to also have the "Περιεχόμενα" words ( standing for Contents ) in Red ... How can that be achieved? I guess it has something to do with

Code: Select all

\makeatletter
Oh by the way the dots in the toc are rendered by

Code: Select all

\usepackage{tocloft}
\renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
\renewcommand\cftchapdotsep{\cftdotsep}%

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Color the contents word

Post by Johannes_B »

Since you did not bother to present a MWE, i can only shoot into the blue.

Code: Select all

\renewcommand{\contentsname}{\textcolor{red}{Περιεχόμενα}}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Tolaso
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

Color the contents word

Post by Tolaso »

Hi Johannes. Thanks but that does not do the trick. I thought than MWE was not necessary in this situation but apparently I am wrong. Here is one

Code: Select all

\documentclass[12pt]{book}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[lmargin=1.3cm, rmargin=1.3cm, vmargin=1.5cm]{geometry}
\renewcommand{\qedsymbol}{$\blacklozenge$}
\usepackage[english,greek]{babel}
\usepackage[utf8]{inputenc}
\usepackage{gensymb}
\usepackage[shortlabels]{enumitem}

%custom parametrisation
\usepackage{titlesec}
\titlelabel{\thetitle.\quad}
\titleformat{\chapter}[hang] 
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter \quad  $-$ }{0.5em}{} 
\usepackage{kmath, kerkis}

%toc style

\usepackage{tocloft}
\renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
\renewcommand\cftchapdotsep{\cftdotsep}%

%hyperlinks
\usepackage{xcolor}
\definecolor{DarkRed}{RGB}{139,0,0}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}

\begin{document}
\chapter{ My first chapter}

\section{My first section }

\end{document}
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Color the contents word

Post by Johannes_B »

Code: Select all

\documentclass[12pt]{book}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage[lmargin=1.3cm, rmargin=1.3cm, vmargin=1.5cm]{geometry}
\renewcommand{\qedsymbol}{$\blacklozenge$}
\usepackage[english,greek]{babel}
\usepackage[utf8]{inputenc}
\usepackage{gensymb}
\usepackage[shortlabels]{enumitem}

%custom parametrisation
\usepackage{titlesec}
\titlelabel{\thetitle.\quad}
\titleformat{\chapter}[hang] 
{\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter \quad  $-$ }{0.5em}{} 
\usepackage{kmath, kerkis}

%toc style

\usepackage{tocloft}
\renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
\renewcommand\cftchapdotsep{\cftdotsep}%

%hyperlinks
\usepackage{xcolor}
\definecolor{DarkRed}{RGB}{139,0,0}
\usepackage{hyperref}
\hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}

\begin{document}
{\pagestyle{empty}
\renewcommand{\contentsname}{\textcolor{DarkRed}{Περιεχόμενα}}
\tableofcontents
}
\chapter{ My first chapter}

\section{My first section }

\end{document}
I set the pagestyle to empty to avaoid an error of a missing color (the name is uppercased). You can have colored headers by defining the color all in uppercase. But if you want all in colour, simply change the textcolor without bothering to change a single event.

Actually, just use

Code: Select all

{\color{DarkRed}\tableofcontents}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Tolaso
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

Color the contents word

Post by Tolaso »

Johannes_B wrote: Actually, just use

Code: Select all

{\color{DarkRed}\tableofcontents}
It is to bang my head on the wall. ...

Thank you!!
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Color the contents word

Post by Stefan Kottwitz »

Hi,

that's actually the easiest way.

By the way, coloring \contentsname would print "Table of Contents" or "Περιεχόμενα" in color everywhere, such as in the header.

The way with babel, also btw., would be

\addto\captionsgreek{\renewcommand{\contentsname}{\textcolor{DarkRed}{Inhalt}}}

Because of page header entries, that are capitalized by default (argh!) there would be an error message since "DarkRed" is capitalized too :-o so an additional \definecolor{DARKRED}{RGB}{139,0,0} fixes that. :D

But, finally, {\color{DarkRed}\tableofcontents} is the best, especially because it colors the page numbers too. Just there may not be an indication any more, that the TOC entries are clickable hyperlinks.

Stefan
LaTeX.org admin
Tolaso
Posts: 37
Joined: Tue Dec 20, 2016 12:23 am

Color the contents word

Post by Tolaso »

Stefan Kottwitz wrote:
Because of page header entries, that are capitalized by default (argh!) there would be an error message since "DarkRed" is capitalized too :-o so an additional \definecolor{DARKRED}{RGB}{139,0,0} fixes that. :D
Could you explain what do you mean by this? What is capitalised?

Edit: Probably you mean the CONTENTS that appear as capital letters. Do I get that right?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Color the contents word

Post by Stefan Kottwitz »

Yes, on the top of subsequent pages of the table of contents, there's the header CONTENTS. Since it's simply uppercased / capitalized, if the color is used within the name it becomes \textcolor{DARKRED}{CONTENTS}, unforeseen. Looks like a fault, but on the other hand styling should not be within text macros anyway.

Stefan
LaTeX.org admin
Post Reply