Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

up vote 10 down vote accepted

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

share|improve this answer
1  
Thanks and great. Will the same strategy work for your answer in tex.stackexchange.com/questions/35825/pretty-table-of-contents also? –  Harish Kumar Mar 13 '12 at 13:04
1  
@HarishKumar: You're welcome. I don't know if the strategy will work there, but I will do some tests. Thanks for the comment. –  Gonzalo Medina Mar 13 '12 at 15:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.