8

I want to change style and color of my Table of Contents to match this:

enter image description here

Note that I use the minitoc package for creating my Table of Contents on a per-chapter basis.

  • Instead of describing your setup, It would really be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that sets up the problem. While solving problems is fun, setting them up is not. Then those trying to help can simply cut and paste your MWE and get started on solving problem. – Peter Grill Nov 18 '12 at 7:04
15

I don't know minitoc well, but here's a way to obtain the desired formatting for the partial ToCs using the titletoc package; once all the settings have been defined in the preamble, all the job is done using a single \PartialToC command:

\documentclass{book}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{titletoc}

\definecolor{secnum}{RGB}{13,151,225}
\definecolor{ptcbackground}{RGB}{212,237,252}
\definecolor{ptctitle}{RGB}{0,177,235}

\titlecontents{lsection}
  [5.8em]{\sffamily}
  {\color{secnum}\contentslabel{2.3em}\normalcolor}{}
  {\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{5pt}%
    \color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{1pt}}

\newcommand\PartialToC{%
\startcontents[chapters]%
\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]
\printcontents[chapters]{l}{1}{\colorbox{ptctitle}{%
  \parbox[t]{\dimexpr\textwidth-2\fboxsep\relax}{%
    \strut\color{white}\bfseries\sffamily\makebox[5em]{%
      Chapter~\thechapter\hfill}Contents}}\vskip5pt}
\end{mdframed}%
}

\begin{document}

\tableofcontents
\chapter{Chapter One}
\PartialToC
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}

\chapter{Chapter Two}
\PartialToC
\section{Section Two One}
\section{Section Two Two}
\section{Section Three Three}

\end{document}

Some images of the partial ToCs:

enter image description here

and

enter image description here

In a comment to the answer has been requested to produce a similar formatting for the general table of contents; in this case, some additional works has to be done:

\documentclass{book}
\usepackage{xcolor}
\usepackage{mdframed}
\usepackage{titletoc}
\usepackage{etoolbox}


\definecolor{secnum}{RGB}{13,151,225}
\definecolor{ptcbackground}{RGB}{212,237,252}
\definecolor{ptctitle}{RGB}{0,177,235}

\pretocmd{\tableofcontents}{\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]}{}{}
\apptocmd{\tableofcontents}{\end{mdframed}}{}{}
\patchcmd{\tableofcontents}{\contentsname}{\color{ptctitle}\contentsname}{}{}

\titlecontents{section}
  [4em]{\sffamily}
  {\color{secnum}\contentslabel{2.3em}\normalcolor}{}
  {\titlerule*[1000pc]{.}\contentspage\\\hspace*{-3em}\vspace*{2pt}%
    \color{white}\rule{\dimexpr\textwidth-20pt\relax}{1pt}}

\titlecontents{lsection}
  [5.8em]{\sffamily}
  {\color{secnum}\contentslabel{2.3em}\normalcolor}{}
  {\titlerule*[1000pc]{.}\contentspage\\\hspace*{-5.8em}\vspace*{2pt}%
    \color{white}\rule{\dimexpr\textwidth-15.5pt\relax}{1pt}}

\makeatletter
\renewcommand*\l@chapter[2]{%
  \ifnum \c@tocdepth >\m@ne
    \addpenalty{-\@highpenalty}%
    \vskip 1.0em \@plus\p@
    \setlength\@tempdima{1.5em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      \colorbox{ptctitle}{\strut%
        \makebox[\dimexpr\textwidth-2\fboxsep-7pt\relax][l]{%
          \color{white}\bfseries\sffamily#1%
          \nobreak\hfill\nobreak\hb@xt@\@pnumwidth{\hss #2}}}\par\smallskip
      \penalty\@highpenalty
    \endgroup
  \fi}
\makeatother
\newcommand\PartialToC{%
\startcontents[chapters]%
\begin{mdframed}[backgroundcolor=ptcbackground,hidealllines=true]
\printcontents[chapters]{l}{1}{\colorbox{ptctitle}{%
  \parbox[t]{\dimexpr\textwidth-2\fboxsep\relax}{%
    \strut\color{white}\bfseries\sffamily\makebox[5em]{%
      Chapter~\thechapter\hfill}Contents}}\vskip5pt}
\end{mdframed}%
}

\begin{document}

\tableofcontents

\chapter{Chapter One}
\PartialToC
\section{Section One One}
\section{Section One Two}
\section{Section One Three}
\section{Section One Four}

\stopcontents[chapters]
\chapter{Chapter Two}
\PartialToC
\section{Section Two One}
\section{Section Two Two}
\section{Section Two Three}

\stopcontents[chapters]
\chapter{Chapter Three}
\PartialToC
\section{Section Three One}
\section{Section Three Two}
\section{Section Three Three}
\section{Section Three Four}
\section{Section Three Five}

\end{document}

An image of the general ToC:

enter image description here

An image of one of the partial ToCs:

enter image description here

  • Very very thanks. how about \tableofcontents ? How to change style of table of content, same this? – mohammad azadi Nov 19 '12 at 7:10
  • 1
    @mohammadazadi please see my updated answer. – Gonzalo Medina Nov 19 '12 at 14:51
  • Excuse me, if i have \subsection, white lines not in exact position. Can you solve this problem, please? – mohammad azadi Nov 19 '12 at 17:25
  • @mohammadazadi sure; please tell me how would the formatting for subsection entries should be. – Gonzalo Medina Nov 20 '12 at 13:46
  • Thank you @GonzaloMedina, i use \titlecontents{subsection} and \titlecontents{lsubsection} and do this. – mohammad azadi Nov 21 '12 at 4:49

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.