Something like this?
\documentclass{book}
\usepackage{tikz}
\usepackage{titlesec}
\usepackage{lipsum}
\makeatletter
\newcommand*{\@chaptercolor}{red!50}
\newcommand*{\chaptercolor}[1]{%
\renewcommand*{\@chaptercolor}{#1}%
}
\titleformat{\chapter}{\sffamily\bfseries\Large}{%
\smash{%
\begin{tikzpicture}[baseline=0]
\useasboundingbox (-1,-1) rectangle (1,1);
\draw[white, line width=4pt, fill=\@chaptercolor] (-1,-1) rectangle (1,1);
\draw (-1,-1) rectangle (1,1);
\node at (0,0) {\Huge\thechapter};
\node at (0,1.3) {Chapter};
\draw[overlay, line width=.2pt] (1.1,0) -- (\dimexpr\linewidth-1cm,0);
\end{tikzpicture}%
}%
}{0mm}{\newline\hspace*{2mm}}
\makeatother
\begin{document}
\chapter{Analysis of Algorithms}
\lipsum[1]
\chaptercolor{blue!50}
\chapter{Another chapter}
\lipsum[2]
\end{document}
You can change the color of the box to any color that is understood by TikZ with \chaptercolor{<color>}
. For example, the above code also outputs the following.
The new color will stay the same until you change it again.
\input
, so it's hard to tell what you've done and what you need to do. Please trim this down to a minimal working example. And please show us your attempt at creating that chapter heading. This site doesn't work well with "Please do this for me" questions.