# Chapter colorized in different colors

Is it possible to give to each chapter a different color coming from something like a color array?

I basically know how to colorize text, but for that purpose the color value is fixed. What I want to do is build up something like an array of colors and then use the color specified in cell 1 for chapter 1, second chapter color in cell 2, etc.

Is something like that doable in Latex?

-
–  Torbjørn T. Feb 22 '13 at 15:30

## Random colors:

\documentclass{scrbook}
\usepackage{pgffor, xcolor}
\usepackage{pgfmath}

\pgfmathdeclarerandomlist{color}{{red!20!yellow}{blue}{yellow}{green!20}{red}{black!20}{orange}}% declare random list
\setkomafont{sectioning}{\pgfmathrandomitem{\randcolor}{color}\color{\randcolor}}% use random list

\begin{document}
%Showcase only!
\let\cleardoublepage\relax
\foreach \x in {A,...,H}{
\chapter{\x}}
\newpage

\end{document}


## Cycle thru list

\documentclass{scrbook}
\usepackage{pgffor, xcolor}
\usepackage{pgfmath}
%The following list must be very long to make sure that pgfmath
%does not try to read a non existing element
% pgfarrys start form index 0 but chapters start form 1 so "dummy" is needed
% in order to have it started form the desired (first) color
% this could be any element cause it't not read anyway
\def\mytemparray{{"dummy" ,"blue!20!green","yellow","green!20","red","black!20","orange","red!20!yellow" ,"blue","yellow","green!20","red","black!20","orange"}}%
\setkomafont{sectioning}{\pgfmathparse{\mytemparray[\thechapter]}\color{\pgfmathresult} }

\begin{document}
%Showcase only!
\let\cleardoublepage\relax
\foreach \x in {A,...,H}{
\chapter{\x}}
\newpage

\end{document}


I used KOMAScript to alter the appearance of the chapters, just to make thing easy for me. Nevertheless the shown techniques should work with any approach to alter the sectioning.

-
That looks very nice! I will try this solution! –  navige Feb 22 '13 at 16:12

You could use

\csname colorchap\Roman{chapter}\endcsname


\newcommand\colorchapA{\color{red}}