2

I'd like to have \part title as in figure 1, centered in 2 lines, but I'm not able to create the right code, even if I didn't find in titletoc manual a specific treatment for \part.

enter image description here

The following code

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}

\titlecontents{part}
[0em]
{\addvspace{1.5pc}\filcenter}
{\thecontentslabel* \huge}
{\huge}
{} % without page number
[\addvspace{.5pc}]

\begin{document}
\tableofcontents
\part{Something as a title}
\end{document}

doesn't produce the result I want. But I'm not sure that titletoc handle at all \part... thnx!

user41063
  • 1,967

2 Answers2

3

book is incompatible with titletoc as it is. Using the patch proposed here you can make it work easily:

enter image description here

\documentclass{book}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{titletoc}

% book -- titletoc patch: https://tex.stackexchange.com/a/454553/134574
\usepackage{etoolbox}
\makeatletter
\patchcmd\@part
  {\thepart}
  {\protect\numberline{\thepart}}
  {}{\FAIL}
\makeatother

\titlecontents{part}
  [0em]
  {\addvspace{1.5pc}\filcenter}
  {\large\partname~\thecontentslabel\endgraf\bfseries}
  {\large}
  {} % without page number
  [\addvspace{.5pc}]

\begin{document}
\tableofcontents
\part{Something as a title}
\end{document}
1

Like this?

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

\titleformat{\part}[display]
  {\Huge\scshape\filright\centering}
  {}
  {20pt}
  {\thispagestyle{empty}}    
 \titlecontents{part}[0pt]{\addvspace{2pc}\centering\large}{\parbox[t][3ex][t]{\linewidth}{\centering\partname~\thecontentslabel} \bfseries}{}{}[\medskip]%

\begin{document}

\tableofcontents

\part{This is a part of a document}

\chapter{Chapter Title}

\end{document} 

enter image description here

Bernard
  • 271,350