How do I change the colors of chapter, section and subsection headings in a book document class? I can change the color of text within the document using the xcolor package and the \color{} command, but it won't work when I include the command in the name of a chapter or section.
So far, I have tried the following within the document:
\chapter{\color{purple}Chapter title}
\chapter{\textcolor{purple}{Chapter title}}
Both of these returned Error: Undefined color `Purple' even though purple is a color included in xcolor. Indeed, when I use a command within the body of the text such as {\color{purple}blah blah blah} the text is output in the appropriate color with no error message.
Is there a way to change the color of chapter and section headings globally in the preamble? Can I change the colors of the chapter and section headings individually so that each chapter heading has different colors?
Text Formatting ⇒ Colored chapter and section headings
- Ijon Tichy
- Posts: 640
- Joined: Mon Dec 24, 2018 10:12 am
Colored chapter and section headings
If you are using the standard book class you need an extra package like titlesec to change fonts or colors of headings. With a more configurable class like the KOMA-Script class scrbook, changing fonts or colors is very easy:
or different colors for different levels:
Code: Select all
\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{blindtext}
\addtokomafont{disposition}{\color{purple}}% color of all headings
\addtokomafont{chapterentry}{\normalcolor}% but not in the ToC
\begin{document}
\tableofcontents
\blinddocument
\end{document}
Code: Select all
\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{blindtext}
\addtokomafont{chapter}{\color{purple}}
\addtokomafont{section}{\color{magenta}}
\addtokomafont{subsection}{\color{green}}
\begin{document}
\tableofcontents
\blinddocument
\end{document}
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. 

Colored chapter and section headings
Does anybody have an idea how to do this *within* the text?
I have to change the section colors for different sections, but all ideas I found are used in the preamble for the whole document...
(I cannot use koma, since I am using a very old latex/lyx)
And since I am using lyx, it would be helpful to change the style for all following sections, instead of using the \section command..
I have to change the section colors for different sections, but all ideas I found are used in the preamble for the whole document...
(I cannot use koma, since I am using a very old latex/lyx)
And since I am using lyx, it would be helpful to change the style for all following sections, instead of using the \section command..