TransWikia.com

Problems formatting part entries in ToC with `titletoc`

TeX - LaTeX Asked on June 11, 2021

I’m trying to understand how to use titletoc and I succeeded in customizing the appearance of chapter entries in the ToC, but I’m failing with part. I can’t understand what I’m doing wrong.

Here’s the code:

documentclass{book}

usepackage{xcolor}
usepackage{titletoc}

titlecontents{chapter}[0pt]{vspace{1em}}{%
  {%
    rlap{largebfseriescolor{blue}thecontentslabel}%
    hspace*{1.5em}%
  }%
  largesffamilyuppercase
}{}{}

titlecontents{part}[0pt]{vspace{1em}}{%
  {%
    rlap{largebfseriescolor{blue}thecontentslabel}%
    hspace*{1.5em}%
  }%
  largesffamilyuppercase
}{}{}

begin{document}

tableofcontents

part{First Part}
chapter{First Chapter}

end{document}

And here’s the output:

output

As you can see the chapter entry looks as wanted (sffamilyuppercase text and colored number). However, the part just doesn’t work.

How can I obtain similar formatting for part as well?

One Answer

You have to redefine the part formatting with titlesec first, because you read in § 3.7, Other Package Options of the documentation:

Standard parts write the toc entry number in a non standard way. You may change that with newparttoc so that titletoc or a similar package can manipulate the entry. (That works only if part has been redefined.)

Therefore, I used titleformat{part}..., so as to reproduce the default formatting in the book (of course, you may change that):

documentclass{book}

usepackage{xcolor}
usepackage[newparttoc]{titlesec}
usepackage{titletoc}

titleformat{part}[display]{centeringbfseriesHuge}{hugepartname~thepart}{2ex}{}

titlecontents{chapter}[0pt]{vspace{1em}}{%
  {%
    rlap{largebfseriescolor{blue}thecontentslabel}%
    hspace*{1.5em}%
  }%
  largesffamilyuppercase
}{}{}

titlecontents{part}[0pt]{vspace{1em}}{%
  {%
    rlap{largebfseriescolor{blue}thecontentslabel}%
    hspace*{1.5em}%
  }%
  largesffamilyuppercase
}{}{}

begin{document}

tableofcontents
part{First Part}
chapter{First Chapter}

end{document} 

enter image description here

Correct answer by Bernard on June 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP