I've been experimenting with coloured swatches around the page number to indicate the chapter using KOMA and TikZ; each chapter also has an em-dash above the text in the same colour as a stylistic flair. The colour is defined prior to each chapter using \chaptercolor{colorname}
, where \chaptercolor
is defined as \newcommand{\chaptercolor}[1]{\colorlet{chaptercolor}{#1}}
.
The \chaptercolor
command has to be called before the chapter to set the line swatch, but this results in the colour swatch for the previous page also changing. I also tried creating a second \swatchcolor
command to change the swatches separately to the chapter line mark, and that results in the page before a new chapter getting whatever the default colour for the swatch is.
How can I avoid this?
I've tried various combinations of KOMA options (e.g. cleardoublepage
, open
) and none of them seem to have the effect I'm after. Not even adding \clearpage
before \colorlet
in the definition of \chaptercolor
seems to work. Here's a MWE that almost works.
\documentclass{scrbook}
\usepackage{scrlayer-scrpage}
%% KOMA options
\KOMAoption{chapterprefix}{true}
\KOMAoption{cleardoublepage}{empty}
\KOMAoption{DIV}{12}
\KOMAoption{draft}{false}
\KOMAoption{fontsize}{11pt}
\KOMAoption{headings}{normal}
\KOMAoption{open}{any}
\KOMAoption{paper}{a4}
\KOMAoption{parskip}{half}
\KOMAoption{twoside}{semi}
\KOMAoption{titlepage}{false}
%% Subfiles for shared preambles
\usepackage[math]{blindtext}
%% Colours - put this before typography so additional named colours can be defined.
\usepackage[table]{xcolor}
\colorlet{darkblue}{blue!40!black}
\usepackage{tikz}
\tikzset{%
small wedge/.pic={
\fill (0, 0) -- ++(-1.2, 0) -- ++(0, 0.6) -- ++(0.6, 0) -- ++(0, 0.6) -- ++(0.6, 0) -- cycle;
},
}
\setkomafont{pagehead}{\small\color{darkblue}\selectfont}
\setkomafont{pagenumber}{\small\color{darkblue}\selectfont}
% Chapters are now "Tutorials"
% Chapters have an em-dash that is \chaptercolor
\newcommand{\chaptercolor}[1]{\colorlet{chaptercolor}{#1}}
\chaptercolor{white}
\renewcommand*{\chapapp}{Tutorial}
\renewcommand*{\chapterheadstartvskip}{\vspace*{-\topskip}}
\renewcommand\chapterformat{{\fontsize{50}{50}\upshape\selectfont\textcolor{chaptercolor}{—}\par\nobreak\chapapp~\thechapter}}
%% Use this to set up the headers and footers
\DeclareNewLayer[
bottommargin,
background,
evenpage,
mode=picture,
contents={%
\putLR{%
\begin{tikzpicture}[remember picture, overlay]
\path pic[fill=chaptercolor, transform shape] at (0,0) {small wedge};
\node[align=right] at (-10mm, 10mm) {\pagemark};
\end{tikzpicture}
}
}]{wedge.even}
\DeclareNewLayer[
bottommargin,
background,
oddpage,
mode=picture,
contents={%
\putLL{%
\begin{tikzpicture}[remember picture, overlay]
\path pic[fill=chaptercolor, transform shape, xscale=-1] at (0,0) {small wedge};
\node[align=left] at (10mm, 10mm) {\pagemark};
\end{tikzpicture}
}
}]{wedge.odd}
\AddLayersAtBeginOfPageStyle{scrheadings}{wedge.odd,wedge.even}%
\pagestyle{scrheadings}
\renewcommand*{\chapterpagestyle}{scrheadings}
\clearscrheadfoot
\lohead{This is a test}
\rehead{\leftmark}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
% % Metadata goes here
\titlehead{Test document}
\subject{Test subject}
\title{Testing of page number colors}
\makeatletter
\let\thetitle\@title
\let\theauthor\@author
\let\thedate\@date
\makeatother
\begin{document}
\frontmatter
\maketitle
\tableofcontents
\mainmatter
\setcounter{secnumdepth}{1}
\chaptercolor{cyan!50}
\chapter{The first chapter of this work}
\blindtext
\blindmathpaper
\blindtext
\chaptercolor{magenta!50}
\chapter{Another chapter to test this thing}
\blindmathpaper
\Blinditemize
\blindtext[10]
\chaptercolor{orange!50}
\chapter{Another chapter to test this thing}
\blindmathpaper
\Blindenumerate
\blindtext[12]
\chaptercolor{green!50}
\chapter{Another chapter to test this thing}
\blindmathpaper
\Blinddescription
\blindtext[20]
\end{document}
I've based parts of my MWE on other questions, but I haven't found or figured out a solution that does exactly what I'm after. Upon further reflection, I like the idea of being able to set both colours separately, but the important thing is that the colour change must only take effect after a new chapter.