# One style for one chapter at a time

I saw some of the questions that may not answer my question, this question is more on decoration-like aspect.

When reading some (coloured illustrated) textbooks, one may find that the chapters have different layout styles. Such as the theme colour and icons.

If I would like to have this feature in my document. What should I do.

If anyone would need a MWE, please request in comment and tell me what sort of MWE is needed. I am not good at providing MWE.

Edit: May I provide some existing examples such as the IB textbook published by OUP, they provide a sample chapter that is coloured. What I would like is each chapter has different headings in different theme colours, and also different page numbers with the corresponding colours (which is on the bottom of the page). I don't need to be the same as the example, however.

• Can you please narrow a little the scope of your question? Describe precisely one or two styles that you would want to have. – Gonzalo Medina May 27 '14 at 2:04
• Is the edit answers your request? – SHY.John May 27 '14 at 2:12
• I'd be very careful with this, changing styles in mid-text can be very jarring. – vonbrand May 28 '14 at 1:43
• @vonbrand I am sorry that I don't quite get it, could you explain it further? – SHY.John May 28 '14 at 1:46

Here's one possibility using titlesec, tikz and fancyhdr. The code needs three runs to stabilize:

\documentclass{book}
\usepackage[margin=2.5cm,centering]{geometry}
\usepackage{lmodern}
\usepackage{tikz}
\usepackage{emptypage}
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

\definecolor{color2}{RGB}{255,197,51}
\definecolor{color3}{RGB}{121,163,65}
\definecolor{color1}{RGB}{53,78,85}
\definecolor{color4}{RGB}{0,27,92}

% page style - headers and footers
\pagestyle{fancy}

\fancyhf{}
\begin{tikzpicture}[remember picture,overlay]
\node[
inner sep=0pt,
fill=\chapterbackcolor,
font=\fontsize{40}{48}\selectfont\color{white}\sffamily,
text width=1.5cm,
anchor=south west,
text height=1.5cm,
text depth=0.2cm,
align=center
]
(chapnum)
{\thechapter};
\node[
fill=\chapterbackcolor,
anchor=south west,
font=\color{white}\sffamily
]
(mark)
at ([xshift=1em]chapnum.south east)
{\leftmark};
\draw[\chapterbackcolor,line width=1pt]
([xshift=1em]mark.south east) -- ++(\paperwidth,0);
\end{tikzpicture}%
}
\begin{tikzpicture}[remember picture,overlay]
\node[
inner sep=0pt,
fill=\chapterbackcolor,
font=\fontsize{40}{48}\selectfont\color{white}\sffamily,
anchor=north east,
align=center
]
(chapimage)
at (current page.north east)
{\includegraphics[height=1.5cm,width=4cm]{example-image-a}};
\node[
inner sep=0pt,
anchor=south east,
font=\color{\chapterbackcolor}\sffamily
]
(mark)
at ([xshift=-1em]chapimage.south west)
{\rightmark};
\draw[\chapterbackcolor,line width=1pt]
([yshift=-1.5ex]mark.south east) -- ++(-\paperwidth,0);
\end{tikzpicture}%
}
\fancyfoot[EL]{%
\begin{tikzpicture}[remember picture,overlay]
\node[
text width=2cm,
text height=0.5cm,
text depth=1.5cm,
fill=\chapterbackcolor!20,
font=\Large\sffamily,
anchor=north east,
align=center
]
{\thepage};
\end{tikzpicture}
}
\fancyfoot[OR]{%
\begin{tikzpicture}[remember picture,overlay]
\node[
text width=2cm,
text height=0.5cm,
text depth=1.5cm,
fill=\chapterbackcolor!20,
font=\Large\sffamily,
anchor=north west,
align=center
]
{\thepage};
\end{tikzpicture}
}

\renewcommand{\chaptermark}[1]{\markboth{\MakeUppercase{#1}}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ \MakeUppercase{#1}}}

% chapter style
\newcommand\chapterbackcolor{}

\renewcommand\chapterbackcolor{%
\ifcase\value{chapter}color4\or color1\or color2\else color3\fi}

\makeatletter
\newcommand\introduction[1]{\def\@introduction{#1}}
\titleformat{\chapter}[block]
{\normalfont\Large\bfseries\sffamily}
{}
{0em}
{%
\begin{tikzpicture}[remember picture,overlay]
\node[fill=\chapterbackcolor,text width=\paperwidth,anchor=north,minimum height=7cm]
(titleback)
at (current page.north)
{};
\node[font=\huge\color{white},anchor=north west]
(title)
at ([xshift=1cm,yshift=-1cm]titleback.north west)
\node[fill=white,anchor=north west,rounded corners,text width=\the\dimexpr\paperwidth-2cm\relax]
(intro)
at ([yshift=-0.5cm]title.south west)
{Introduction\\\vspace*{-.35\baselineskip}%
\begin{minipage}[c][2.2cm][c]{\linewidth}
\begin{multicols}{2}
\normalfont\normalsize\@introduction
\end{multicols}
\end{minipage}%
};
\end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}[block]
{\normalfont\Large\bfseries\sffamily}
{}
{0em}
{%
\begin{tikzpicture}[remember picture,overlay]
\node[fill=\chapterbackcolor,text width=\paperwidth,anchor=north,minimum height=7cm]
(titleback)
at (current page.north)
{};
\node[font=\huge\color{white},anchor=north west]
(title)
at ([xshift=1cm,yshift=-1cm]titleback.north west)
{\MakeUppercase{#1}};
\end{tikzpicture}%
}
\makeatother
\titlespacing*{\chapter}
{0pt}{0pt}{5cm}

\newcommand\Text{% dummy text just for the example
Quisque ullamcorper placerat ipsum. Cras nibh. Morbi vel justo vitae lacus
tincidunt ultrices. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. In
hac habitasse platea \columnbreak dictumst. Integer tempus convallis augue. Etiam facilisis.
Nunc elementum fermentum wisi. Aenean placerat. Ut imperdiet, enim sed
gravida sollicitudin, felis odio placerat quam, ac pulvinar elit purus eget enim.
}

\begin{document}

\mbox{}\thispagestyle{empty}\clearpage% just for the example

\tableofcontents

\introduction{\Text}
\chapter{circular motion and gravitation}
\section{Circular motion}
\lipsum[1-28]

\introduction{\Text}
\chapter{circular motion and gravitation}
\section{Circular motion}
\lipsum[1-28]

\introduction{\Text}
\chapter{circular motion and gravitation}
\section{Circular motion}
\lipsum[1-18]

\end{document}


The different colors are selected using a \chapterbackcolor command that takes its values using a simple \ifcase on the value of the chapter counter; colors have been defined using \definecolor from the xcolor package; in its actual form, there's only four colors: one to be used for unnumbered chapters and the other three for the first three numbered chapters. One can simply define more colors and add them in the \ifcase clause for more chapters:

\definecolor{color2}{RGB}{255,197,51}
\definecolor{color3}{RGB}{121,163,65}
\definecolor{color1}{RGB}{53,78,85}
\definecolor{color4}{RGB}{0,27,92}

\renewcommand\chapterbackcolor{%
\ifcase\value{chapter}color4\or color1\or color2\else color3\fi}


All the elements of the chapter titles and the headers were designed basically placing the elements at desired locations using \nodes inside a tikzpicture.

There are still room for improvement: the page numbering for the first page of each chapter (a redefinition of the plain page style easily achieved using fancyhdr features), a way to change the header image from chapter to chapter but compared to what has been done up to this point, those are easy tasks.

• Error You can't use \dimexpr in restricted horizontal mode. – Micky K May 27 '14 at 4:02
• Error You can't use \dimexpr in restricted horizontal mode – Ahmad May 27 '14 at 4:22
• @SKKhan Please update your LaTeX system; at least PGF/TikZ. The code I gave works with PGF version 3.0. I edited the answer and the new code should work for you. – Gonzalo Medina May 27 '14 at 4:23
• @Ahmad Please see my previous comment. I updated the code so now it should work with older versions of PGF, but please update your packages. – Gonzalo Medina May 27 '14 at 4:23
• @Ahmad how i update the PGF packages i am trying but still same error given. – Micky K May 27 '14 at 7:48