0

I color a page with tikzpicture and I want the book title can be placed at the center of the page colored. But when I write the code

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

the book title begin a new page.

enter image description here

2

\maketitle automatically inserts a \newpage. To prevent this, we can do the same as shown in https://tex.stackexchange.com/a/86255/143325, i.e. locally override the definition of \newpage so that it does nothing.

Note that the tikzpicture has to come before the \maketitle or it will overlay the text.

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

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.