# Creating a fancy chapter style using tikz

Could anyone propose a way to achieve the following chapter style with the given document as a starting point? (The number "1" is the chapter number)

\documentclass{book}

\usepackage{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}

\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}

\titleformat{\chapter}[display]
{}{\rule{.7\textwidth}{2pt}}{0pt}
\begin{document}

\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}

\end{document}


Use the option explicit with titlesec. This code gives you something very close to your picture.

\documentclass{book}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}
\newcommand\myfancychapter{\tikz[baseline=(CHAP.base),very thick]{
\draw[use as bounding box,draw=white,fill=white] (0,0) rectangle (2cm,2cm);
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP) at
(1cm,\baselineskip+1ex) {\Huge{\textbf{\textsf{\thechapter}}}};
\draw[draw=gray!30!white,fill=gray!30!white] (2cm,0cm) rectangle (\textwidth,2cm);
\draw[black, ultra thick](0,1.2cm) -- (\textwidth,1.2cm);
\draw[black, ultra thick](2cm,0cm) -- (2cm,2cm);
}}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}

\titleformat{\chapter}
{\normalfont}{\myfancychapter}{1em}{\LARGE{\textbf{#1}}}

\begin{document}

\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}

\end{document}


I just moved the number below the line because I think this looks better. But with tikz you have full control.

EDIT: Here is a minimal damage' way of moving the section number above the line. I also had to make the box larger.

\documentclass{book}
\usepackage{tikz}
\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in]{geometry}
\newcommand\myfancychapter{\tikz[baseline=(CHAP.base),very thick]{
\draw[use as bounding box,draw=white,fill=white] (0,0) rectangle (2cm,2.5cm);
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP) at
(1cm,\baselineskip+1ex) {\phantom{\Huge{\textbf{\textsf{\thechapter}}}}};
\node[fill=white,minimum width=1.5cm,outer sep=0pt,rounded corners] (CHAP2) at
(1cm,1.8cm) {\Huge{\textbf{\textsf{\thechapter}}}};
\draw[draw=gray!30!white,fill=gray!30!white] (2cm,0cm) rectangle (\textwidth,2.5cm);
\draw[black, ultra thick](0,1.2cm) -- (\textwidth,1.2cm);
\draw[black, ultra thick](2cm,0cm) -- (2cm,2.5cm);
}}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}

\titleformat{\chapter}
{\normalfont}{\myfancychapter}{1em}{\LARGE{\textbf{#1}}}

\begin{document}

\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}

\end{document}


2ND EDIT: Built in @egreg's suggestion. (Grazie!)

• Thank you! How would you go about moving the number above the line? – wrb98 Nov 29 '17 at 16:01
• I added a minimal damage version. It can be improved, though. – user121799 Nov 29 '17 at 16:16
• I usually recommend something like \titleformat{\chapter}{\normalfont}{\mychapterheader}{1em}{\LARGE\bfseries} (no explicit option) along with \newcommand\mychapterheader{<the code for the picture>}. Cleaner coding. – egreg Nov 29 '17 at 16:37
• @egreg You're right. – user121799 Nov 29 '17 at 16:56

I don't think you need a sledgehammer for this: tabularx, booktabs and colortbl will do:

\documentclass{book}

\usepackage[explicit]{titlesec}
\usepackage[titles]{tocloft}
\usepackage[paperheight=9.3in,paperwidth=6.85in, showframe]{geometry}
\usepackage{tabularx, booktabs}
\usepackage[table, svgnames]{xcolor}
\renewcommand\cftchapfont{\normalfont}
\renewcommand\cftchappagefont{\normalfont}

\titleformat{\chapter}[block]
{\huge\bfseries}{}{0pt}
{\setlength{\extrarowheight}{3pt}\begin{tabularx}{\textwidth}{ >{\filcenter}p{1cm}!{\vrule width 2pt} >{\columncolor{Gainsboro!50!Lavender}[\tabcolsep][0pt]\filcenter}X@{}}\thechapter & \\ \specialrule{2pt}{0pt}{0pt}&#1\end{tabularx}}[\addvspace{-1pt}]

\begin{document}

\mainmatter
\chapter{Test Chapter}
\section{Test Subsection}

\end{document}