Error with xcolor package

I wouldn't apply those format changes directly in the argument of the sectional units since the formatting changes will also appear in the ToC and in the headers producing undesired results; the following minimal working example reproduces the problem mentioned:

\documentclass{report}
\usepackage[dvipsnames]{xcolor}
\usepackage{lipsum}

\pagestyle{headings}

\begin{document}

\chapter{\color{Maroon}My Title}
\lipsum[1-30]

\end{document}

since \MakeUppercase is used to produce the headers, LaTeX sees the color name as "MAROON" (uppercased) and this triggers the error message

! Package xcolor Error: Undefined color `MAROON'.

To prevent this kind of problems, I suggest using the sectsty or the titlesec packages to perform changes to the sectional unit formatting. An example with sectsty:

\documentclass{report}
\usepackage[dvipsnames]{xcolor}
\usepackage{sectsty}
\usepackage{lipsum}% just to generate text for the example

\chapterfont{\color{Maroon}}

\begin{document}

\chapter{My Title}
\lipsum[4]

\end{document}

enter image description here

Now that additional information has been given in the comments, it's clear that a different approach is needed since the fncychap package is beeing used to produce the chapter titles in the Conny style. The MWE reproducing the problem:

\documentclass{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[Conny]{fncychap}
\usepackage{lipsum}

\begin{document}

\chapter{\color{Maroon}My Title}
\lipsum[1-30]

\end{document}

In this case, the modification to the title color can be done by using \ChTitleVar of only the title in the heading must receive color:

\documentclass{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[Conny]{fncychap}
\usepackage{lipsum}

\ChTitleVar{\centering\Huge\color{Maroon}}

\begin{document}

\chapter{My Title}
\lipsum[1-30]

\end{document}

enter image description here

If the color change must affect all the heading, a possible solution can be obtained by redefining \DOCH:

\documentclass{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[Conny]{fncychap}
\usepackage{lipsum}

\makeatletter
\renewcommand{\DOCH}{%
    \color{Maroon}\mghrulefill{3\RW}\par\nobreak
    \vskip -0.5\baselineskip
    \mghrulefill{\RW}\par\nobreak
    \CNV\FmN{\@chapapp}\space \CNoV\thechapter
    \par\nobreak
    \vskip -0.5\baselineskip
   }
\makeatother

\begin{document}

\chapter{My Title}
\lipsum[1-30]

\end{document}

enter image description here


I wouldn't use fncychap for any reason whatsoever. But anybody is free to harm themselves as they like. :)

Add the following declaration after having loaded xcolor:

\colorlet{MAROON}{Maroon}

A simple way to avoid coloring the headings and the table of contents entry is to use the optional argument to \chapter:

\chapter[Title]{\color{Maroon}Title}

An "automated" way that preserves the possibility of specifying a different "short title" can be as follows:

\makeatletter
\let\latex@chapter\@chapter
\renewcommand\@chapter[2][]{%
  \if\relax\detokenize{#1}\relax
    \latex@chapter[#2]{\color{Maroon}#2}
  \else
    \latex@chapter[#1]{\color{Maroon}#1}
  \fi}
\makeatother

Of course, changing the color of "Chapter 1" or other parts of the chapter title is another thing.

Tags:

Color