我用 tikzpicture 给一页纸上色,我想让书名放在彩色页面的中央。但是当我写代码时
\documentclass{book}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\title{\Huge C++ \\\qquad\textcolor{RedOrange}{Primer}}
\newlength\amount
\setlength{\amount}{0.33\paperheight}
\begin{document}
\maketitle
\begin{tikzpicture}[remember picture,overlay]
\fill[green] (current page.north west) rectangle ([yshift=-\amount]current page.north east);
\fill[yellow] ([yshift=-\amount]current page.north west) rectangle ([yshift=-2\amount]current page.north east);
\fill[red]([yshift=-2\amount]current page.north west) rectangle ([yshift=-3\amount]current page.north east);
\end{tikzpicture}
\end{document}
书名开始新的一页。
答案1
\maketitle
自动插入\newpage
。为了防止这种情况,我们可以按照所示执行相同的操作https://tex.stackexchange.com/a/86255/143325,即本地覆盖的定义,\newpage
以致于它不执行任何操作。
请注意,tikzpicture
必须前或者它将\maketitle
覆盖文本。
\documentclass{book}
\usepackage[dvipsnames]{xcolor}
\usepackage{tikz}
\title{\Huge C++ \\\qquad\textcolor{RedOrange}{Primer}}
\newlength\amount
\setlength{\amount}{0.33\paperheight}
\begin{document}
\begin{tikzpicture}[remember picture,overlay]
\fill[green] (current page.north west) rectangle ([yshift=-\amount]current page.north east);
\fill[yellow] ([yshift=-\amount]current page.north west) rectangle ([yshift=-2\amount]current page.north east);
\fill[red]([yshift=-2\amount]current page.north west) rectangle ([yshift=-3\amount]current page.north east);
\end{tikzpicture}
{\let\newpage\relax\maketitle} %<--------
\end{document}