1

In this MWE, that involves a very attractive chapter heading style found here, and also an elegant chapter thumb setting found here, developed by Mr. Gonzalo Medina, I wanted to get the chapter name, section names and subsection names to show up in a box along the edge of pages like this:

enter image description here

and the page headers (except on the chapter title page) to look like this (with the ocre colored box):

enter image description here

\documentclass[11pt,fleqn]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{mathtools,amsfonts,amssymb,amsthm}
\usepackage[most]{tcolorbox}
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\usepackage{fourier}
\usepackage[explicit]{titlesec}

\renewcommand\thechapter{\arabic{chapter}}

\newcommand\chapnumfont{% 
  \fontsize{380}{130}\color{myblueii}\selectfont%
}

\newcommand\chapnamefont{%
  \normalfont\color{white}\scshape\small\bfseries
}

\titleformat{\chapter}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\stepcounter{chapshift}%
  \begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {\thechapter};%
  \node[
      anchor=south east,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont\thechapter};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titleformat{name=\chapter,numberless}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {};%
  \node[
      anchor=south east,minimum width=2in,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titlespacing*{\chapter}{0pt}{0pt}{3.5in}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{3.5in}

\usetikzlibrary{calc}
\pagestyle{plain}

\newcounter{chapshift}
\addtocounter{chapshift}{-1}

\newcommand\BoxColor{myblueii}

\def\subsectiontitle{}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
\renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}

\usepackage{etoolbox,fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}}
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage}
\fancyhead[LO]{\textcolor{mybluei} \rightmark%
\begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=-1pt,rectangle,text width=1cm,
    text height=28cm,align=center,anchor=north east]
  at ($ (current page.north east) $)
  {\rotatebox{90}{\parbox{18cm}{%
   \centering\textcolor{white}{\bfseries\scshape\thechapter.\leftmark \hspace{2cm}\rightmark\hspace{2cm}\thesubsection~\subsectiontitle}}}};
  \end{tikzpicture}}
\fancyhead[RE]{\textcolor{mybluei}\leftmark%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=28cm,align=center,anchor=north west]
  at ($ (current page.north west) $)
  {\rotatebox{90}{\parbox{18cm}{%
    \centering\textcolor{white}{\bfseries\scshape\thechapter.\leftmark \hspace{2cm}\rightmark\hspace{2cm}\thesubsection~\subsectiontitle}}}};
  \end{tikzpicture}}
\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}
\renewcommand{\footrulewidth}{.5pt}
\fancyfoot[LE,RO]{\footnotesize\bfseries\itshape Foot 1}
\fancyfoot[C]{\footnotesize\bfseries Foot 2}
\fancyfoot[RE,LO]{\footnotesize\bfseries\itshape Foot 3}

\fancypagestyle{plain}{%
  \fancyhf{}% 
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}

\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\makeatother

\begin{document}
\chapter{This is how it all began}
\section{Introduction}
\lipsum[1-3]
\subsection{Sub Introduction}
\lipsum[1-3]

\chapter{This is how it all ended}
\section{Time to say "Goodbye"}
\lipsum

\end{document}
3
  • What problem have you run into exactly? I'm not really clear how your MWE relates to your question. For example, the code creates footers but you don't mention footers. Moreover, I'm not sure how the 2 styles are meant to be combined given that they will obviously clash. Finally, if you are using code written by somebody else in your MWE, that's obviously fine but it is only courteous to attribute it and give its author credit. (In some cases, attribution is also a legal requirement. But I think not being rude is the more important factor here.)
    – cfr
    Commented Sep 8, 2015 at 22:27
  • @cfr, I added the original author's name (as you correctly stated that should be done for the sake of courtesy and respect). I attempted to work on the header style but got stuck and left the minimum, thinking that can be a starting point to an eventual solution for my desired output.
    – Joe
    Commented Sep 9, 2015 at 3:48
  • Updated code with modified "side bar" colored box. I get an undesired output when there is no subsection. How can I work around this issue?
    – Joe
    Commented Sep 9, 2015 at 18:07

1 Answer 1

3

To prevent printing of the subsection name when not yet defined, just test whether the subsection is counter is zero before printing:

\ifnum\value{subsection}=0\else\thesubsection~\subsectiontitle\fi

Sample output

\documentclass[11pt,fleqn]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{mathtools,amsfonts,amssymb,amsthm}
\usepackage[most]{tcolorbox}
\definecolor{ocre}{RGB}{52,177,201}
\definecolor{ultramarine}{RGB}{0,45,97}
\definecolor{mybluei}{RGB}{0,173,239}
\definecolor{myblueii}{RGB}{63,200,244}
\definecolor{myblueiii}{RGB}{199,234,253}

\usepackage{fourier}
\usepackage[explicit]{titlesec}

\renewcommand\thechapter{\arabic{chapter}}

\newcommand\chapnumfont{%
  \fontsize{380}{130}\color{myblueii}\selectfont%
}

\newcommand\chapnamefont{%
  \normalfont\color{white}\scshape\small\bfseries
}

\titleformat{\chapter}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\stepcounter{chapshift}%
  \begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {\thechapter};%
  \node[
      anchor=south east,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {\chapnumfont\thechapter};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titleformat{name=\chapter,numberless}
  {\normalfont\huge\filleft}
  {}
  {0pt}
  {\begin{tikzpicture}[remember picture,overlay]
  \fill[myblueiii]
    (current page.north west) rectangle ([yshift=-13cm]current page.north east);
  \node[
      fill=mybluei,
      text width=2\paperwidth,
      rounded corners=6cm,
      text depth=18cm,
      anchor=center,
      inner sep=0pt] at (current page.north east) (chaptop)
    {};%
  \node[
      anchor=south east,minimum width=2in,
      inner sep=0pt,
      outer sep=0pt] (chapnum) at ([xshift=-20pt]chaptop.south)
    {};
  \node[
      anchor=south,
      inner sep=0pt] (chapname) at ([yshift=2pt]chapnum.south)
  {};
  \node[
      anchor=north east,
      align=right,
      inner xsep=0pt] at ([yshift=-0.5cm]chapname.east|-chapnum.south)
  {\parbox{.7\textwidth}{\raggedleft#1}};
  \end{tikzpicture}%
  }

\titlespacing*{\chapter}{0pt}{0pt}{3.5in}
\titlespacing*{name=\chapter,numberless}{0pt}{0pt}{3.5in}

\usetikzlibrary{calc}
\pagestyle{plain}

\newcounter{chapshift}
\addtocounter{chapshift}{-1}

\newcommand\BoxColor{myblueii}

\def\subsectiontitle{}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize#1}{}}
\renewcommand{\subsectionmark}[1]{\def\subsectiontitle{#1}}

\usepackage{etoolbox,fancyhdr}

\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{\markboth{\sffamily\normalsize\bfseries \ #1}{}}
\renewcommand{\sectionmark}[1]{\markright{\sffamily\normalsize\thesection\hspace{5pt}#1}{}}
\fancyhf{} \fancyhead[LE,RO]{\sffamily\normalsize\thepage}
\fancyhead[LO]{\textcolor{mybluei} \rightmark%
\begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=-1pt,rectangle,text width=1cm,
    text height=28cm,align=center,anchor=north east]
  at ($ (current page.north east) $)
  {\rotatebox{90}{\parbox{18cm}{%
   \centering\textcolor{white}{\bfseries\scshape\thechapter.\leftmark \hspace{2cm}\rightmark\hspace{2cm}\thesubsection~\subsectiontitle}}}};
  \end{tikzpicture}}
\fancyhead[RE]{\textcolor{mybluei}\leftmark%
  \begin{tikzpicture}[overlay,remember picture]
  \node[fill=\BoxColor,inner sep=0pt,rectangle,text width=1cm,
    text height=28cm,align=center,anchor=north west]
  at ($ (current page.north west) $)
  {\rotatebox{90}{\parbox{18cm}{%
    \centering\textcolor{white}{\bfseries\scshape\thechapter.\leftmark \hspace{2cm}\rightmark\hspace{2cm}\ifnum\value{subsection}=0\else\thesubsection~\subsectiontitle\fi}}}};
  \end{tikzpicture}}
\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}
\newcommand{\footrulecolor}[1]{\patchcmd{\footrule}{\hrule}{\color{#1}\hrule}{}{}}
\renewcommand{\headrulewidth}{.5pt}
\addtolength{\headheight}{2.5pt}
\renewcommand{\footrulewidth}{.5pt}
\fancyfoot[LE,RO]{\footnotesize\bfseries\itshape Foot 1}
\fancyfoot[C]{\footnotesize\bfseries Foot 2}
\fancyfoot[RE,LO]{\footnotesize\bfseries\itshape Foot 3}

\fancypagestyle{plain}{%
  \fancyhf{}%
  \renewcommand{\headrulewidth}{0pt}
  \renewcommand{\footrulewidth}{0pt}
}

\makeatletter
\renewcommand{\cleardoublepage}{
\clearpage\ifodd\c@page\else
\hbox{}
\vspace*{\fill}
\thispagestyle{empty}
\newpage
\fi}
\makeatother

\begin{document}
\chapter{This is how it all began}
\section{Introduction}
\lipsum[1-3]
\subsection{Sub Introduction}
\lipsum[1-3]

\chapter{This is how it all ended}
\section{Time to say "Goodbye"}
\lipsum

\end{document}

You must log in to answer this question.

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