4

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}

\newcommand{\amount}{4in}   %%<---- adjust


\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?

enter image description here

enter image description here

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

The following MWE will do:

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

\newcommand{\amount}{4in}   %%<---- adjust

\makeatletter
\let\oldchapterheadstart\chapterheadstart
\def\chapterheadstart#1{%
  \AddThispageHook{%
    \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}
  }%
  \oldchapterheadstart{#1}%  \vspace*{50\p@}%
}

\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.

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

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}
  \makeevenhead{chapterfirstpage}{}{\chapterpagebackground}{}
  \makeoddhead{chapterfirstpage}{}{\chapterpagebackground}{}

\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
\newcommand{\amount}{\if@mainmatter 4in\else 3.5in\fi}   %%<---- adjust
\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

enter image description here

enter image description here

4
  • Thank you. I could see warnings when compiling, but did not know how to solve.
    – juanuni
    Jul 19 '16 at 2:23
  • Well, trying with your code I get five warnings message ...
    – juanuni
    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 ...
    – juanuni
    Jul 20 '16 at 6:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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