2

How can I center the part name in the TOC ?

I want the TOC to print :

                                 Partie I - First part

Chapitre 1 - First chapter

Chapitre 2 - Second one

Instead I have :

Partie I - First part

Chapitre 1 - First chapter

Chapitre 2 - Second one

Here is a minimal code :

\documentclass[12pt,a4paper]{book}

% Part name in TOC
\usepackage{tocloft}
\usepackage{xpatch}
\renewcommand\cftpartpresnum{\centering}
\renewcommand\cftpartleader{}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\renewcommand{\thepart}{ Partie \Roman{part} --\hspace{-.4cm}}
\renewcommand\cftchappresnum{Chapitre\ }
\renewcommand\cftchapaftersnum{\hfill--\hfill}
\renewcommand\cftchapnumwidth{3.2cm}
\renewcommand\cftdotsep{2}
%\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %Si on veut mettre des pointillés
%\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} 
\newcommand\Bpart[1]{\part{\texorpdfstring{}{}#1}}
\newcommand\Bchapter[1]{\chapter{\texorpdfstring{}{Chapitre \arabic{chapter} -- }#1}}

\begin{document}

\tableofcontents

\part{First part}
\chapter{First chapter}
\chapter{Second chapter}

\end{document} 

In fact I don't konow at all how to center the part name so I tried a desperate centering without success.

How can I fix it ?

Thank you.

  • 1
    What about the part page number? – egreg May 18 '16 at 11:31
  • I don't want the page number for the part in TOC ^^ – John Marjan May 18 '16 at 15:35
3

You can do this with

\renewcommand\cftpartpresnum{\hfil}
\renewcommand\cftpartleader{\hfil}

complete code

\documentclass[12pt,a4paper]{book}

% Part name in TOC
\usepackage{tocloft}
\usepackage{xpatch}
\renewcommand\cftpartpresnum{\hfil}
\renewcommand\cftpartleader{\hfil}
\addtocontents{toc}{\cftpagenumbersoff{part}}
\renewcommand{\thepart}{ Partie \Roman{part} --\hspace{-.4cm}}
\renewcommand\cftchappresnum{Chapitre\ }
\renewcommand\cftchapaftersnum{\hfill--\hfill}
\renewcommand\cftchapnumwidth{3.2cm}
\renewcommand\cftdotsep{2}
%\renewcommand{\cftpartleader}{\cftdotfill{\cftdotsep}} %Si on veut mettre des pointillés
%\renewcommand{\cftchapleader}{\cftdotfill{\cftdotsep}} 
\newcommand\Bpart[1]{\part{\texorpdfstring{}{}#1}}
\newcommand\Bchapter[1]{\chapter{\texorpdfstring{}{Chapitre \arabic{chapter} -- }#1}}

\begin{document}

\tableofcontents

\part{First part}
\chapter{First chapter}
\chapter{Second chapter}

\end{document} 

enter image description here

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.