4

I would like to get this style enter image description here

Currently my MWE is

\documentclass[openany,fleqn]{book}
\usepackage{tikz}
\usepackage{titlesec}
\usepackage{xcolor}

\usepackage[margin=2cm,width=176mm,height=250mm]{geometry}
\usetikzlibrary{calc} 

% -------------------------------------------------
% Chapter heading macro
% -------------------------------------------------
\newcommand{\chapterheader}[1]{%
  \begin{tikzpicture}[remember picture, overlay]
    % Full-width background bar
    \fill[black] (-5,0) rectangle (\paperwidth,3.3);
    \fill[gray!30] (3,0) rectangle (\paperwidth,3.3);

    % Diamond with chapter number (slightly lowered)
    \coordinate (C) at (3,.1);
    \path[fill=white, draw=gray, line width=0.4pt, rotate around={45:(C)},rounded corners=5pt]
      ($(C)+(-1.15,-1.15)$) rectangle ($(C)+(1.15,1.15)$);

    % Chapter number
    \node[text=red, font=\bfseries\fontsize{46}{48}\selectfont] at (C) {\thechapter};

    % "Chapter" label (rotated along the diamond)
    \node[rotate=45, anchor=west, text=white,
      font=\Large\bfseries, opacity=0.95] at (1.2,0.25) {CHAPTER};

    % Title text (right side, strong sans serif)
    \node[anchor=west, text=black, font=\bfseries\fontsize{30}{32}\selectfont] 
      at (5,0.95) {\parbox[t]{0.7\textwidth}{#1}};
  \end{tikzpicture}%
  \vspace{2.2cm}%
}

% -------------------------------------------------
% Apply to \chapter
% -------------------------------------------------
\titleformat{\chapter}[display]
  {\normalfont}
  {}
  {0pt}
  {\chapterheader}

\titlespacing*{\chapter}{0pt}{0pt}{1cm}

% -------------------------------------------------
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{Algebra}
\section{Numerical Concepts}
\section{Equations and Inequalities}
\section{Partial Fractions}
\section{Permutations and Combinations}
\section{Series}
\section{Complex Numbers}
\end{document}

Which is giving enter image description here

Thanks in advance

3
  • 1
    you use \thechapter unconditionally. don't use it for unnumbered chapters. doesn't titlesec provide some way to format starred headings? Commented Nov 5 at 21:04
  • Use \node[text=red, font=\bfseries\fontsize{46}{48}\selectfont] at (C) {\ifnum\thechapter > 0 \thechapter \else\fi}; Commented Nov 5 at 21:22
  • It would be easier to not use titlesec, but rather modify \@makechapterhead and \@makeschapterhead separately. Commented Nov 6 at 14:27

1 Answer 1

6

Fix by adding a check on the value of the chapter counter:

\newcommand{\chapterheader}[1]{%
  \begin{tikzpicture}[remember picture, overlay]
    % Full-width background bar
    \fill[black] (-5,0) rectangle (\paperwidth,3.3);
    \fill[gray!30] (3,0) rectangle (\paperwidth,3.3);

    % Diamond with chapter number (slightly lowered)
    \coordinate (C) at (3,.1);
    \path[fill=white, draw=gray, line width=0.4pt, rotate around={45:(C)},rounded corners=5pt]
      ($(C)+(-1.15,-1.15)$) rectangle ($(C)+(1.15,1.15)$);

    % Chapter number only if positive
    \ifnum\value{chapter}>0
      \node[text=red, font=\bfseries\fontsize{46}{48}\selectfont] at (C) {\thechapter};
    % "Chapter" label (rotated along the diamond)
      \node[rotate=45, anchor=west, text=white,
        font=\Large\bfseries, opacity=0.95] at (1.2,0.25) {CHAPTER};
    \fi

    % Title text (right side, strong sans serif)
    \node[anchor=west, text=black, font=\bfseries\fontsize{30}{32}\selectfont]
      at (5,0.95) {\parbox[t]{0.7\textwidth}{#1}};
  \end{tikzpicture}%
  \vspace{2.2cm}%
}

contents

chapter 1

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.