3
\documentclass[11pt, twosides]{book}
\usepackage[a4paper, top=.5cm]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace}
\usepackage{mathpazo}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage{sectsty}
\usepackage{url, lipsum}
\usepackage{etoolbox}
\usepackage[explicit]{titlesec}
\usepackage{epigraph}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\titleformat{\chapter}[display]
  {\normalfont\huge}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
\fill[top color=green, bottom color=blue] 
(16,-23) rectangle (18.5,7);
\node[
    anchor= east,
    xshift=1cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.east) {\fontsize{30}{36}\sffamily\selectfont#1};
\node[
    anchor= east,
    inner xsep=3cm,
    outer sep=0pt,
    font=\color{blue}]%,
    at ([yshift=.5cm]current page.east|-titlerect.east)
     {\fontsize{80}{86}\bfseries\thechapter};
\node[
    anchor= east,
    xshift=11.5cm,
        yshift=-11cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.east) {\fontsize{30}{36}\scshape\selectfont\rotatebox{90}{\color{white}#1}};
  \end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
    \fill[top color=green, bottom color=blue] 
    (16,-25) rectangle (18.5,7);
  \node[
   anchor=west,
    rectangle,
    minimum height=4cm,
    text width=\paperwidth,
    xshift=-\the\dimexpr\oddsidemargin+1in\relax,
    outer sep=0pt] (titlerect) {};
  \node[
    anchor=south west,
    xshift=6cm,
        yshift=2cm,
    text width=\textwidth] 
   at (titlerect.south west) {\sffamily\Huge#1};
    \node[
    anchor= east,
    xshift=11.5cm,
        yshift=-11cm,
    text width=\textwidth] 
    at ([yshift=5pt]titlerect.east) {\fontsize{30}{36}\scshape\selectfont\rotatebox{90}{\color{white}#1}};
  \end{tikzpicture}%
  }[]
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}
\titlespacing*{\chapter}
  {0pt}{-20pt}{60pt}
\titleformat{\section}[display] 
{\bfseries\normalsize}
{}
{5pt}
{\color{blue}\thesection~~ #1}
\titleformat{name=\section, numberless}[display]
{\bfseries\normalsize}
{}
{5pt}
{#1}

\titleformat{\subsection}[display]
{\itshape\normalsize}
{}
{5pt}
{\color{blue}\thesection~~ #1}

\fancypagestyle{plain}
{
   \fancyhf{}
   \fancyfoot{}
   \renewcommand{\headrulewidth}{0 mm}
}

\title{Title}
\author{Author}
\date{}
\textwidth=13cm
\begin{document}

\maketitle

\chapter{Random}

\section{Lipsum}

\lipsum[2]

\subsection{Subsection}

\lipsum[1]
\end{document}
4
  • 2
    For the sake of completeness, the MWE from the question seems to be similar (identical?) to the code in this answer.
    – leandriis
    Commented Aug 26, 2020 at 18:51
  • 2
    @leandriis . yes, this code from answer on question Customizing chapter style with tikz - Vertical rectangle. but I can't add comment , because my reputation. Commented Aug 26, 2020 at 19:13
  • 1
    I left a comment for you there
    – AndréC
    Commented Aug 26, 2020 at 19:24
  • 1
    @AndréC . thanks a lot Commented Aug 26, 2020 at 19:25

1 Answer 1

8

It looks like the node titlerec is supposed to be the rectangle created with the initial \fill command. We can replace this with a node by using the tikz fit library and the page nodes from tikzpagenodes to fix the problem.

The code below now compiles without errors to give the desired output. Of course, initially, the hard work was done in the post https://tex.stackexchange.com/a/374634/134144. This said, I have rationalised the code, made better use of tikzpagenodes, made the numbered and numberless versions consistent and taken out some code that I thought unnecessary. Once this is done the code produces:

enter image description here

Here is the updated code:

\documentclass[11pt, twosides]{book}
\usepackage[a4paper, top=.5cm]{geometry}
\usepackage[myheadings]{fullpage}
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx, wrapfig, subcaption, setspace}
\usepackage{mathpazo}
\usepackage[T1]{fontenc}
\usepackage[font=small, labelfont=bf]{caption}
\usepackage[protrusion=true, expansion=true]{microtype}
\usepackage{sectsty}
\usepackage{url, lipsum}
\usepackage{etoolbox}
\usepackage[explicit]{titlesec}
\usepackage{epigraph}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{tikzpagenodes}
\titleformat{name=\chapter}[display]
  {\normalfont\huge}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
    \coordinate (SE) at ([xshift=-50]current page.south east);
    \node[top color=green, bottom color=blue, 
        fit=(current page.north east)(SE)](titlerect){};
    \node[font=\fontsize{30}{36}\sffamily\selectfont] 
        at (current page text area.north){#1};
    \node[xshift=-25, font=\fontsize{80}{86}\bfseries\color{blue}]
        at (current page text area.north east-|titlerect.west)
        {\thechapter};
    \node[xshift=25, 
          font=\fontsize{30}{36}\scshape\selectfont\color{white}]
       at (current page.center-|titlerect.west) {\rotatebox{90}{#1}};
 \end{tikzpicture}%
}
\titleformat{name=\chapter,numberless}[display]
  {\normalfont\huge}
  {}
  {20pt}
  {%
  \begin{tikzpicture}[remember picture,overlay]
    \node[top color=green, bottom color=blue, 
        fit=(current page.north east)(SE)](titlerect){};
    \node[font=\fontsize{30}{36}\sffamily\selectfont] 
       at (current page text area.north){#1};
    \node[xshift=25, 
       font=\fontsize{30}{36}\scshape\selectfont\color{white}]
       at (current page.center-|titlerect.west) {\rotatebox{90}{#1}};
  \end{tikzpicture}%
}
\titlespacing*{\chapter}{0pt}{-20pt}{60pt}
\titleformat{\section}[display]
{\bfseries\normalsize}
{}
{5pt}
{\color{blue}\thesection~~ #1}
\titleformat{name=\section, numberless}[display]
{\bfseries\normalsize}
{}
{5pt}
{#1}

\titleformat{\subsection}[display]
{\itshape\normalsize}
{}
{5pt}
{\color{blue}\thesection~~ #1}

\fancypagestyle{plain}
{
   \fancyhf{}
   \fancyfoot{}
   \renewcommand{\headrulewidth}{0 mm}
}

\title{Title}
\author{Author}
\date{}
\begin{document}

\chapter{Random}

\section{Lipsum}

\lipsum[2]

\subsection{Subsection}

\lipsum[1]

\chapter*{Random}

\section{Lipsum}

\lipsum[2]

\subsection{Subsection}

\lipsum[1]

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .