I have a color switching function that looks like this
\definecolor{chap1}{RGB}{68, 114, 148}
\definecolor{chap2}{RGB}{10,130,124}
\definecolor{chap3}{RGB}{250,72,46}
\definecolor{chap4}{RGB}{244,163,46}
\usepackage{etoolbox}
\newcommand{\basecolor}{
\ifcase\arabic{chapter} black\or chap1\or chap2\or chap3\or chap4\else black\fi%
}
\newcommand{\chaptercolor}{\basecolor}
This lets me use \chaptercolor
anywhere to get the color that has been chosen for this chaper depending on its position in the document. Works great, except for one thing.
I cannot get it to work with plots.
Take this simple plot as an example:
\tikzset{>=stealth}
\begin{tikzpicture}
\begin{axis}[
domain=0:1, range=0:1,
axis lines=none,
]
\addplot [->] plot coordinates {(0,0) (0,1)};
\addplot [->, color=\chaptercolor, fill=\chaptercolor, draw=\chaptercolor] plot coordinates {(0,0) (1,0)};
\end{axis}
\end{tikzpicture}
This gives me the error Package xcolor Error: Undefined color ` chap2'.
With all the odd symbols in it.
If I use the color chap2
directly instead it works fine. It would also be great to have the plots always use \chaptercolor
maybe by using \tikzset{}
, but so far that gives even worse error messages.
Any input on how to fix this, or perhaps even a different approach to cycling the colors?
Edit:
Adding an identical color with a space in front of its name solves the problem.
\definecolor{ chap1}{RGB}{68, 114, 148}
\definecolor{ chap2}{RGB}{10,130,124}
\definecolor{ chap3}{RGB}{250,72,46}
\definecolor{ chap4}{RGB}{244,163,46}
\definecolor{chap1}{RGB}{68, 114, 148}
\definecolor{chap2}{RGB}{10,130,124}
\definecolor{chap3}{RGB}{250,72,46}
\definecolor{chap4}{RGB}{244,163,46}
A little inelegant, but it's not too bad since it's only in the preamble.
\value{chapter}
rather than\arabic{chapter}
, just a tip.