1

I am writing a document in the bookclass and want to have the name of the parts centered in the TOC. They should also be displayed without the part number and without page numbers. I have seen some solutions for other classes, but these do not seem to work. The code

\documentclass{book}
\usepackage{titlesec}
\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength\@tempdima{3em}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode
       \hspace*{\fill}\centering\large\bfseries #1\hspace*{\fill}\llap{#2}}\par
       \nobreak
         \global\@nobreaktrue
         \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
  \fi}
\makeatother
\renewcommand{\partname}{}
\makeatletter
\titleformat{\part}[display]
  {\Huge\scshape\filright\centering}
  {}
  {20pt}
  {\thispagestyle{empty}}
\makeatother
\begin{document}
\tableofcontents
\part{This is a part of a document}
\end{document}

puts the part name centered, but how can I get rid of the numbers?

4

It is much simpler to do with titletoc than fiddling with a cryptic code:

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

\titleformat{\part}[display]
  {\Huge\scshape\filright\centering}
  {}
  {20pt}
  {\thispagestyle{empty}}
\titlecontents{part}[0pt]{\addvspace{2pc}\centering\large\bfseries}{}{}{}%

\begin{document}

\tableofcontents

\part{This is a part of a document}

\chapter{Chapter Title}

\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.