Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
Related: tex.stackexchange.com/questions/18635/… –  Torbjørn T. Feb 22 '13 at 15:30
add comment

2 Answers 2

up vote 4 down vote accepted

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}

enter image description here

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}

enter image description here

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.

share|improve this answer
    
That looks very nice! I will try this solution! –  navige Feb 22 '13 at 16:12
add comment

You could use

\csname colorchap\Roman{chapter}\endcsname

as your color command in your chapter heading code and then you need

\newcommand\colorchapA{\color{red}}
\newcommand\colorchapB{\color{blue}}
\newcommand\colorchapC{\color{green}}

to set up as many colors as you need.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.