4

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{\large\bfseries\color{blue}\thecontentslabel}%
    \hspace*{1.5em}%
  }%
  \large\sffamily\uppercase
}{}{}

\titlecontents{part}[0pt]{\vspace{1em}}{%
  {%
    \rlap{\large\bfseries\color{blue}\thecontentslabel}%
    \hspace*{1.5em}%
  }%
  \large\sffamily\uppercase
}{}{}

\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 (\sffamily\uppercase text and colored number). However, the \part just doesn't work.

How can I obtain similar formatting for \part as well?

1 Answer 1

5

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]{\centering\bfseries\Huge}{\huge\partname~\thepart}{2ex}{}

\titlecontents{chapter}[0pt]{\vspace{1em}}{%
  {%
    \rlap{\large\bfseries\color{blue}\thecontentslabel}%
    \hspace*{1.5em}%
  }%
  \large\sffamily\uppercase
}{}{}

\titlecontents{part}[0pt]{\vspace{1em}}{%
  {%
    \rlap{\large\bfseries\color{blue}\thecontentslabel}%
    \hspace*{1.5em}%
  }%
  \large\sffamily\uppercase
}{}{}

\begin{document}

\tableofcontents
\part{First Part}
\chapter{First Chapter}

\end{document} 

enter image description here

0

You must log in to answer this question.

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