5

I am trying to make my own style of chapter. It was nearly successful...However,two problems arised.First, the style also appears in content that's not what I want.Second, the position of the blue bar is wrong. How can I solve the two problems? Thanks! Here is an example code:

\documentclass{book}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{xcolor}

\titleformat{\chapter}[display]{%
\begin{tikzpicture}
\path [fill=blue!20] (0,1) rectangle (\textwidth,2);
\end{tikzpicture}
\flushleft%
 }{\fontsize{96pt}{96pt}\bfseries\thechapter}{0pt}{\Huge\color{blue}}

\begin{document}
\tableofcontents
\chapter{example1}
\section{hahaha}
\chapter{example2}
\section{sososos}
\end{document}

enter image description here enter image description here

3

Like this?

\documentclass{book}
\usepackage{titlesec}
\usepackage{tikz}
\usepackage{xcolor}

\titleformat{\chapter}[display]{%
\flushleft%
 }{
\begin{tikzpicture}
\node[anchor=south west] (chap) at (0.1,1.3){\fontsize{96pt}{96pt}\bfseries\thechapter};
\path [fill=blue!20] (0,1) rectangle (\textwidth,0);
\path(0,-0.2); 
\end{tikzpicture} 
}{-3mm}{\Huge\color{blue}}


\begin{document}
\tableofcontents
\chapter{example1}
\section{hahaha}
\chapter{example2}
\section{sososos}
\end{document}

enter image description here

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.