9

I was just trying to add some fancy part name in TOC using a code I got from a post in this site. Here is what I added.

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{kpfonts}
\usepackage{tikz}
\usepackage{titletoc}
%------------------------------------------
\contentsmargin{0cm}
%------------------------------------------
\titlecontents{part}[0pc]
{\addvspace{13pt}%
\begin{tikzpicture}%
\draw[help lines,step=.4cm,color=blue] (0,0) grid (2.4,1.2);%
\pgftext[left,x=.1cm,y=.6cm]{\Large\sc \partname};%
\fill[fill=white,draw=blue] (1.8,.6) circle (0.4cm);%
\pgftext[x=1.8cm,y=.6cm]{\protect\thepart};%
\end{tikzpicture}\\\color{blue}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;\large\bfseries \thecontentspage}%
%------------------------------------------
\titlecontents{chapter}[0pc]
{\addvspace{30pt}%
\begin{tikzpicture}%
\draw[help lines,step=.4cm,color=red] (0,0) grid (3.2,1.2);%
\pgftext[left,x=.1cm,y=.6cm]{\Large\sc chapter};%
\fill[fill=white,draw=red] (2.7,.6) circle (0.35cm);%
\pgftext[x=2.7cm,y=.6cm]{\thecontentslabel};%
\end{tikzpicture}\\\color{red}\large\sc\bfseries}%
{}
{}
{\;\titlerule\;\large\bfseries \thecontentspage}%
%------------------------------------------
\titlecontents{section}[2.4pc]
{\addvspace{1pt}}
{\contentslabel[\thecontentslabel]{2.4pc}}
{}
{\hfill\small \thecontentspage}
%------------------------------------------
[]
\titlecontents*{subsection}[4pc]
{\addvspace{-1pt}\small}
{}
{}
{\ --- \small\thecontentspage}
[ \textbullet\ ][]
%-------------------------
\begin{document}
\tableofcontents
\part{Part One}
\chapter{(title chapter 1)}
\section{(title section 1)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
\section{(title section 2)}
\subsection{(title sub-section 1)}
\subsection{(title sub-section 2)}
%--------------------------
\end{document} 

Here is what I get:

enter image description here

My problem: The part number I is not coming inside the circle after PART instead it is coming below with the part name.

How to get the part number inside the circle like in chapter? What else I have to add?

10

The redefinitions for part using titletoc will work as soon as you use the newparttoc option for the titlesec package and provide a suitable redefinition for \part using titlesec; in the following example (just for the example's sake) I gave a quick redefinition of \part using titlesec just to illustrate the effect on the part entries in the ToC:

\documentclass{book}
\usepackage{tikz}
\usepackage[newparttoc]{titlesec}
\usepackage{titletoc}

%------------------------------------------
\contentsmargin{0cm}
%------------------------------------------

\titleformat{\part}[display]
{\normalfont\huge\bfseries}{\thepart}{20pt}{\Huge}

\titlecontents{part}[0pc]
{
\protect\addvspace{13pt}%
\begin{tikzpicture}%
\draw[help lines,step=.4cm,color=blue] (0,0) grid (2.4,1.2);%
\pgftext[left,x=.1cm,y=.6cm]{\Large\scshape\partname};%
\fill[fill=white,draw=blue] (1.8,.6) circle (0.4cm);%
\node at(1.8cm,.6cm) {I};%
\end{tikzpicture}\\\color{blue}\large\scshape\bfseries
\thepart}%
{}
{l}
{$\;$\titlerule$\;$\large\bfseries\thecontentspage}%

\begin{document}
\tableofcontents
\part{Part One}

\end{document}

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy