LaTeX forum ⇒ Text FormattingColor the contents word

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

Color the contents word

Postby Tolaso » Tue Oct 31, 2017 10:29 am

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

  1. \usepackage{xcolor}
  2. \definecolor{DarkRed}{RGB}{139,0,0}
  3. \usepackage{hyperref}
  4. \hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}


and everything goes well ... Take a look

preview.png
preview.png (109.58 KiB) Viewed 234 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

  1. \makeatletter


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

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

User avatar
Johannes_B
Site Moderator
Posts: 3586
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Oct 31, 2017 10:35 am

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

  1. \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: 31
Joined: Tue Dec 20, 2016 12:23 am

Postby Tolaso » Tue Oct 31, 2017 10:55 am

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

  1. \documentclass[12pt]{book}
  2. \usepackage{amsmath}
  3. \usepackage{amsfonts}
  4. \usepackage{amssymb}
  5. \usepackage{amsthm}
  6. \usepackage[lmargin=1.3cm, rmargin=1.3cm, vmargin=1.5cm]{geometry}
  7. \renewcommand{\qedsymbol}{$\blacklozenge$}
  8. \usepackage[english,greek]{babel}
  9. \usepackage[utf8]{inputenc}
  10. \usepackage{gensymb}
  11. \usepackage[shortlabels]{enumitem}
  12.  
  13. %custom parametrisation
  14. \usepackage{titlesec}
  15. \titlelabel{\thetitle.\quad}
  16. \titleformat{\chapter}[hang]
  17. {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter \quad $-$ }{0.5em}{}
  18. \usepackage{kmath, kerkis}
  19.  
  20. %toc style
  21.  
  22. \usepackage{tocloft}
  23. \renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
  24. \renewcommand\cftchapdotsep{\cftdotsep}%
  25.  
  26. %hyperlinks
  27. \usepackage{xcolor}
  28. \definecolor{DarkRed}{RGB}{139,0,0}
  29. \usepackage{hyperref}
  30. \hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}
  31.  
  32. \begin{document}
  33. \chapter{ My first chapter}
  34.  
  35. \section{My first section }
  36.  
  37. \end{document}

User avatar
Johannes_B
Site Moderator
Posts: 3586
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Tue Oct 31, 2017 11:20 am

  1. \documentclass[12pt]{book}
  2. \usepackage{amsmath}
  3. \usepackage{amsfonts}
  4. \usepackage{amssymb}
  5. \usepackage{amsthm}
  6. \usepackage[lmargin=1.3cm, rmargin=1.3cm, vmargin=1.5cm]{geometry}
  7. \renewcommand{\qedsymbol}{$\blacklozenge$}
  8. \usepackage[english,greek]{babel}
  9. \usepackage[utf8]{inputenc}
  10. \usepackage{gensymb}
  11. \usepackage[shortlabels]{enumitem}
  12.  
  13. %custom parametrisation
  14. \usepackage{titlesec}
  15. \titlelabel{\thetitle.\quad}
  16. \titleformat{\chapter}[hang]
  17. {\normalfont\huge\bfseries}{\chaptertitlename\ \thechapter \quad $-$ }{0.5em}{}
  18. \usepackage{kmath, kerkis}
  19.  
  20. %toc style
  21.  
  22. \usepackage{tocloft}
  23. \renewcommand\cftchapaftersnum{.}% adds dot after chapter title in ToC
  24. \renewcommand\cftchapdotsep{\cftdotsep}%
  25.  
  26. %hyperlinks
  27. \usepackage{xcolor}
  28. \definecolor{DarkRed}{RGB}{139,0,0}
  29. \usepackage{hyperref}
  30. \hypersetup{colorlinks=true, linkbordercolor=DarkRed,linkcolor=DarkRed}
  31.  
  32. \begin{document}
  33. {\pagestyle{empty}
  34. \renewcommand{\contentsname}{\textcolor{DarkRed}{Περιεχόμενα}}
  35. \tableofcontents
  36. }
  37. \chapter{ My first chapter}
  38.  
  39. \section{My first section }
  40.  
  41. \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
  1. {\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: 31
Joined: Tue Dec 20, 2016 12:23 am

Postby Tolaso » Tue Oct 31, 2017 11:28 am

Johannes_B wrote:Actually, just use
  1. {\color{DarkRed}\tableofcontents}


It is to bang my head on the wall. ...

Thank you!!

User avatar
Stefan Kottwitz
Site Admin
Posts: 8541
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Oct 31, 2017 5:34 pm

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
Site admin

Tolaso
Posts: 31
Joined: Tue Dec 20, 2016 12:23 am

Postby Tolaso » Tue Oct 31, 2017 9:20 pm

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: 8541
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Tue Oct 31, 2017 10:07 pm

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
Site admin


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests