两种颜色(或更多)的页面,用于开始章节

两种颜色(或更多)的页面,用于开始章节

我试图根据以下情况将每章的第一页制作成两种颜色https://tex.stackexchange.com/a/236952/14423。这对于目录来说效果很好,但对于每章的第一页效果不佳,如您所见:

主要的:

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

介绍.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 和 app.tex 没有线条。显然我做错了什么。这是什么?

在此处输入图片描述

在此处输入图片描述

答案1

以下 MWE 将执行:

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

tikzpicture我已经添加了里面的内容\AddThisPageHook{},现在将其插入到宏中\chapterheadstart{}。这会为所有章节(包括未编号的章节)添加颜色层。

答案2

在您的 MWE 中,tikzpicture章节标题已打印时会插入。因此它会覆盖章节标题。

我建议chapterfirstpage根据页面样式定义自己的页面样式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}

运行两次即可获得

在此处输入图片描述

在此处输入图片描述

相关内容