# Two colors (or more) of page, for beginning chapter

I'm trying to make the first page of each chapter in two colors according https://tex.stackexchange.com/a/236952/14423. This works well for the table of contents, but does not work well for the first page of each chapter, as you can see:

Main:

\documentclass[letterpaper,showtrims,draft,11pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{tikz}

\begin{document}

\frontmatter
\begin{tikzpicture}[remember picture,overlay]
\fill[green] ([yshift=-\amount]current page.north west) rectangle (current page.north east);
\fill[yellow] (current page.south west) rectangle ([yshift=-\amount]current page.north east);
\end{tikzpicture}
\tableofcontents

\include{intro}

\mainmatter

\include{cap1}
\include{cap2}

\backmatter

\include{app}

\end{document}


intro.tex :

\chapter{Introducci\'on}

\begin{tikzpicture}[remember picture,overlay]
\fill[green] ([yshift=-\amount]current page.north west) rectangle (current page.north east);
\fill[yellow] (current page.south west) rectangle ([yshift=-\amount]current page.north east);
\end{tikzpicture}

\lipsum[1-5]


cap1.tex :

\chapter{Cap\'itulo Uno}

\begin{tikzpicture}[remember picture,overlay]
\fill[green] ([yshift=-\amount]current page.north west) rectangle (current page.north east);
\fill[yellow] (current page.south west) rectangle ([yshift=-\amount]current page.north east);
\end{tikzpicture}

\lipsum[1-5]


cap2.tex and app.tex have no lines. Obviously something I'm doing wrong. What is it?

• I almost got blind by your choice of colors. :-( Jul 18 '16 at 12:58
• hahahaha is my fault, I just copy a code from the link above ... Jul 19 '16 at 1:52

The following MWE will do:

\documentclass[letterpaper,showtrims,draft,11pt]{memoir}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{tikz}
\usepackage{everypage}

\makeatletter
\begin{tikzpicture}[remember picture,overlay]
\fill[green] ([yshift=-\amount]current page.north west) rectangle (current page.north east);
\fill[yellow] (current page.south west) rectangle ([yshift=-\amount]current page.north east);
\end{tikzpicture}
}%
}

\makeatother

\begin{document}

\frontmatter
\tableofcontents

\include{intro}

\mainmatter

%\include{cap1}
\chapter{Introducci\'on}

\lipsum[1-5]

%\include{cap2}
\chapter{Cap\'itulo Uno}

\lipsum[1-5]

\backmatter

\include{app}

\end{document}


I have added the content of tikzpicture inside \AddThisPageHook{}, which is now inserted inside the macro \chapterheadstart{}. This will now add color layer to all the chapters including unnumbered.

• I was watching with everypage package and its commands, although I could not solve it. Thank you. Jul 19 '16 at 2:24
• Well, trying with your code I get five warnings message ... Jul 19 '16 at 4:14

In your MWE the tikzpicture is inserted when the chapter title was already printed. So it overlays the chapter title.

I would suggest to define an own page style chapterfirstpage based on page style plain.

\documentclass[letterpaper,showtrims,draft,11pt]{memoir}
\usepackage[english]{babel}
\usepackage{tikz}

\aliaspagestyle{chapter}{chapterfirstpage}

\copypagestyle{chapterfirstpage}{plain}

\newcommand*\chapterpagebackground{%
\begin{tikzpicture}[remember picture,overlay]
\fill[topcolor] ([yshift=-\amount]current page.north west) rectangle (current page.north east);
\fill[bottomcolor] (current page.south west) rectangle ([yshift=-\amount]current page.north east);
\end{tikzpicture}%
}

\makeatletter
\makeatother
\colorlet{topcolor}{green}
\colorlet{bottomcolor}{yellow}

\usepackage{blindtext}% dummy text
\begin{document}

\frontmatter
\tableofcontents
\blinddocument

\mainmatter
\blinddocument
\blinddocument

\backmatter
\blinddocument
\end{document}


Run twice to get

• Thank you. I could see warnings when compiling, but did not know how to solve. Jul 19 '16 at 2:23
• Well, trying with your code I get five warnings message ... Jul 19 '16 at 4:04
• In the second run I do not get any warning if I use an uptodate MiKTeX or an uptodate TL 2016.
– esdd
Jul 19 '16 at 8:48
• I'm updating my LaTeX version ... Jul 20 '16 at 6:58