# colorful background of the chapters in ToC without ''tocloft'' package

I would like to create a table of contents where the chapters appear with a colorful background just like attached Image, and i hope to do this without tocloft ( without packages or with titletoc )

an attempt by Beginner

\documentclass{book}
\usepackage{fancyhdr}
\usepackage{titletoc}
\usepackage[svgnames]{xcolor}

\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\arabic{subsection}.\arabic{section}}

\pagestyle{fancy}
\cfoot{\thepage}

\titlecontents*{chapter}
[0pt]
{\colorbox{MidnightBlue}{\textcolor{white}%
{\chaptername\ \thecontentslabel}}}
{}
{\colorbox{MidnightBlue}{\textcolor{white}%
{\hspace{7.5cm}\contentspage}}}

\makeatletter
\let\stdl@chapter\l@chapter
\renewcommand*{\l@chapter}[2]{%
\stdl@chapter{\colorbox{MidnightBlue}{\textcolor{white}{#1}}}{\textcolor{MidnightBlue}{#2}}}
\makeatother

\begin{document}

\tableofcontents

\chapter{Chapter One}
\section{Section Two}
\subsection{Subsection Two}

\end{document}

-
Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Christian Hupfer Aug 15 '14 at 10:33
Please explain why you wish to accomplish your objective without using a specialized LaTeX package. – Mico Aug 15 '14 at 11:32

The easiest way apart from deep hacks, is to put a tighttcolorbox around the \l@chapter command, which is redefined and called internally with the standard values. However, this introduces some vertical spacing above and below the chapter toc entries.

The colours are hardcoded at the moment.

\documentclass{book}%
\usepackage{blindtext}%
\usepackage[svgnames]{xcolor}%

\usepackage{fancyhdr}%
\usepackage{tcolorbox}

\makeatletter
\let\standardlistchapter\l@chapter%

\renewcommand*{\l@chapter}[2]{%
\begin{tcolorbox}[colback={MidnightBlue},
coltext={white},
boxrule=0pt,
boxsep=0pt,%
left=0pt,top=-10pt,
right=0pt,
bottom=0pt,
arc=0pt,
auto outer arc]
\standardlistchapter{\textcolor{white}{#1}}{\textcolor{white}{#2}}%
\end{tcolorbox}%
}%

\renewcommand\thesection{\arabic{section}.}
\renewcommand\thesubsection{\arabic{subsection}.\arabic{section}}

\pagestyle{fancy}
\cfoot{\thepage}

\makeatother

\begin{document}
\tableofcontents%

\chapter{Chapter one}

\section{First}

\blindtext[5]

\chapter{Chapter two}

\section{First}

\blindtext[5]

\end{document}


-