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!

2 Answers 2

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}
3
  • thanx, solved! only... Is book class incompatible with titletoc only for \part handling?
    – user41063
    Commented Oct 16, 2018 at 14:06
  • 1
    @user41063 Not completely incompatible, but without the patch titletoc cannot detect the \thecontentslabel of the \part. Try commenting out the patch to see what happens. But as far as I know this is the only problem. Commented Oct 16, 2018 at 14:08
  • thanx, very kind of you
    – user41063
    Commented Oct 16, 2018 at 14:12
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

2
  • Perhaps a ~ between \partname and \thecontentslabel :) Commented Oct 16, 2018 at 14:20
  • @PhelypeOleinik: Oh! yes. I guess I messed up modifying an old version. I'll fix that in a moment. Thanks!
    – Bernard
    Commented Oct 16, 2018 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .