# Center the “part name” in the table of contents

I want to change in the table of contents the look of the parts. I reproduced on Word what I want :

I've looked into the site if the question was already answered but I didn't found what I want.

All I want is to center the part name in the TOC and also get rid of the page number. I am using the book class and I don't want to use other document classes.

Thank you.

EDIT. Here is my MWE :

\documentclass{book}
\begin{document}
\tableofcontents
\part{First part}
\chapter{A first chapter}
\chapter{A second one}
\part{Second part}
\chapter{A third one}
\chapter{The last one}
\end{document}


Here is my preambule with titlesec :

\documentclass{book}

%Redifining paragraph spacing and thus spacing in the TOC
\usepackage{titlesec}
\usepackage{parskip}
\setlength{\parskip}{ 0.4\baselineskip}
\titlespacing\section{0pt}{9pt plus 4pt minus 2pt}{5pt plus 2pt minus 2pt}
\titlespacing\subsection{0pt}{9pt plus 4pt minus 2pt}{2pt plus 2pt minus  2pt}
\titlespacing\subsubsection{0pt}{9pt plus 4pt minus 2pt}{2pt plus 2pt minus 2pt}
\setlength\parindent{0pt}

% Here the code of Christian Hupfer
\usepackage{tocloft}
\renewcommand\cftpartpresnum{\hfill}
\renewcommand\cftpartleader{\hfill}

\begin{document}
\tableofcontents
\part{First part}
\chapter{A first chapter}
\chapter{A second one}
\part{Second part}
\chapter{A third one}
\chapter{The last one}
\end{document}

• The usual way is to provide a starter document – user31729 Apr 27 '16 at 12:10
• I think your question has been answered here. – BenjaminH Apr 27 '16 at 12:14
• I must haven't write the right words in my research. – M.LTA Apr 27 '16 at 13:22
• The duplicate is only for the koma classes, not book. – Andrew Swann Jan 23 '18 at 9:15

## 2 Answers

Since the part number should be centered as well, I choose to use a patch for the \addcontentsline within \@part -- note this is only working of the \secnumdepth is greater than -1.

\documentclass{book}

\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@part}{%
\addcontentsline{toc}{part}{\thepart\hspace{1em}#1}%%
}{%
\addtocontents{toc}{\bfseries\protect\centering\thepart\hspace{1em}#1\par}%
}{}{}
\makeatother

\begin{document}
\tableofcontents

\part{How to provide a MWE}

\chapter{Foo}

\part{How not to be seen}

\chapter{Arthur Gumby}

\end{document}


• Well, so rapid and precise, thanks a lot, exactly what I want ! – M.LTA Apr 27 '16 at 13:18
• Hummm... it works with MWEs but when I use the package titlesec it doesn't work anymore. To be precise I use the titlesec package for changing vertical spaces in the TOC because I redefined the parskip. I put the code in my last edition of my initial message. – M.LTA Apr 27 '16 at 13:38
• @M.LTA: That wasn't in your question above. titlesec is a very strange package, in my point of view – user31729 Apr 27 '16 at 13:43
• No that wasn't my question above ... consider it a new question if you want ^^ Still I didn't realized that this package would interact. – M.LTA Apr 27 '16 at 13:45

To get the part number centered, I had to use the tocloft package.

\documentclass{book}
\usepackage{tocloft}
\renewcommand\cftpartpresnum{\hfill}
\renewcommand\cftpartleader{\hfill}
\begin{document}
\tableofcontents
\clearpage

\part{Parte the First}

\section{Introduction}
\section{Next Section}

\part{Parte the Second}

\section{Introduction}
\section{Next Section}
\end{document}


Here is without tocloft and without centering of the part number. I also needed to introduce \cpart that uses the optional argument of \part to achieve toc centering.

\documentclass[]{book}
\newcommand\cpart[1]{\part[\hfill#1\hfill]{#1}}
\begin{document}
\tableofcontents
\clearpage

\cpart{Parte the First}

\section{Introduction}
\section{Next Section}

\cpart{Parte the Second}

\section{Introduction}
\section{Next Section}
\end{document}


• Hi, you didn't answer my precise question, but still I like that you provided me with different style of table of contents ! Thank you ! – M.LTA Apr 27 '16 at 13:19