I know how to change the colour of a section name using for example
\section{\color{Red} Foobar}
but that still leaves the section number in black. Is there any way to change the colour of the numbers of the sections, subsections, etc?
I know how to change the colour of a section name using for example
\section{\color{Red} Foobar}
but that still leaves the section number in black. Is there any way to change the colour of the numbers of the sections, subsections, etc?
I'm sure there is some package that does this, but the simplest way is to redefine the \thesection command:
\renewcommand\thesection{\color{red}\arabic{section}}
or if you also want the chapter number:
\renewcommand\thesection{\color{red}\thechapter.\arabic{section}}
Similar commands work for \thechapter, \thesubsection, etc.
EDIT: A maybe unintended side effect of this is that it also color every reference to the section. To just change it in the section header you can use
\makeatletter
\renewcommand\@seccntformat[1]{\color{red} {\csname the#1\endcsname}\hspace{0.5em}}
\makeatother
In any case you might want to have a look at section 2.2 of the LaTeX Companion and the titlesec package.
It actually depends on what class you use, for instance, for article.cls, you can have:
\documentclass{article}
\usepackage{color}
\makeatletter
\renewcommand\section{\@startsection {section}{1}{\z@}%
{-3.5ex \@plus -1ex \@minus -.2ex}%
{2.3ex \@plus.2ex}%
{\normalfont\Large\bfseries\color{red}}}
\makeatother
\begin{document}
\tableofcontents
\section{This is a section}
This is a test
\end{document}
sectsty package offers a coherent and unified way of customizing headings. Anyway, you got my +1.
– chl
Jan 11 '11 at 12:30
\color there is not recommended because of an inserted "whatsit". See https://tex.stackexchange.com/a/101643/13552.
– Jonathan Komar
Jul 05 '18 at 06:57
xcolor Error: undefined color 'RED'error for me, regardless of any color I enter. – Anti Earth Jun 02 '16 at 09:04xcolororcolorpackage loaded andredcolor defined? In other words, does{\color{red}Foo}anywhere in your document typeset red Foo? – Crowley Jul 19 '16 at 17:49