3

I want to remove the dot after the Part number in the TOC. So far, only Koma-Script classes worked.

\documentclass{mwbk}
\usepackage{titletoc}


\titlecontents{part}
[0pt]
{\addvspace{2pc}%
    \bfseries\centering}%
{\contentsmargin{0pt}%
    \bfseries
    \huge \partname~\thecontentslabel
    \\[12pt]%
    \Large\itshape}
{\contentsmargin{0pt}%
    \huge}
{%\quad\contentspage
    }
%[\addvspace{.5pc}]

%I've also tried this, it didn't work
%\usepackage{tocloft}
%\renewcommand{\cftpartaftersnum}{}
%%\renewcommand{\cftpartaftersnum}{:}
%\renewcommand\cftpartpresnum{Part~}


\begin{document}

\tableofcontents    
\part{title}
\end{document}

2 Answers 2

2

For titletoc to work with \part you have to redefine the formatting of part in titlesec, so that it yields the same result as the class. Here is an attempt:

\documentclass{mwbk}

\usepackage[toctitles, newparttoc]{titlesec}
\usepackage{titletoc}
\titleformat{\part}[display]{\bfseries\filcenter}{\huge\partname~\Roman{part}}{30pt}{\Large\itshape}
\titlecontents{part}
[0pt]
{\addvspace{2pc}%
    \bfseries\centering}%
{\contentsmargin{0pt}%
    \bfseries
    \huge \partname~\thecontentslabel
    \\[12pt]%
    \Large\itshape}
{\contentsmargin{0pt}%
    \huge}
{,\quad\contentspage
    }
[\addvspace{.5pc}]

\begin{document}

\tableofcontents
\part{title}
\chapter{ first chapter}

\end{document} 

enter image description here

4
  • your solutions works for chapters in the TOC, but it messes with \section formatting in the text.
    – user9424
    Commented Jun 27, 2016 at 1:51
  • @Joseph: Strange… I didn't re-define \thepart. What happens with \section?
    – Bernard
    Commented Jun 27, 2016 at 8:14
  • Text formatting in sections (in the text, not in the TOC) is lost, with erros "missing number" and "illegal unit of measure" .
    – user9424
    Commented Jun 27, 2016 at 12:42
  • I don't know why, but somehow your approach started to work perfectly and egreg's threw some error warning (although the result is similar).
    – user9424
    Commented Jul 4, 2016 at 22:11
2

The mwbk class is not really compatible with titletoc or tocloft. A lower level strategy seems necessary.

\documentclass{mwbk}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \mw@tocskip{-1}{.6\baselineskip}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode\normalsize
       %\def\numberline##1{##1\enspace}% <--- removed
       \let\numberline\partnumberline  % <--- added
       \hfil\bfseries #1\hfil\null %\hb@xt@\@pnumwidth{\hss #2}%
      }\par
      \nobreak
      \global\@nobreaktrue
      \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \addvspace{.4\baselineskip}%
  \fi}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

The redefinition of \numberline is different from the default. Basically, we now remove the period, isolating what's before and after it.

enter image description here

Shorter, with etoolbox:

\documentclass{mwbk}
\usepackage{etoolbox}

\makeatletter
\patchcmd{\l@part}
  {\def\numberline}
  {\let\numberline\partnumberline\def\blurbunused}
  {}{}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

The patch needs to define a macro, because parts with ##1 cannot be patched like this. Better with regexpatch:

\documentclass{mwbk}
\usepackage{regexpatch}

\makeatletter
\xpatchcmd{\l@part}
  {\def\numberline##1{##1\enspace}}
  {\let\numberline\partnumberline}
  {}{}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{#1#2\enspace}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

If you want “Part I” on one line and “title” on the next line, centered, first think twice about it; if you insist on it,

\documentclass{mwbk}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \mw@tocskip{-1}{.6\baselineskip}%
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      {\leavevmode\normalsize\normalfont\bfseries
       \let\numberline\partnumberline  % <--- added
       \centering #1\par
      }
      \nobreak
      \global\@nobreaktrue
      \everypar{\global\@nobreakfalse\everypar{}}%
    \endgroup
    \addvspace{.4\baselineskip}%
  \fi}
\def\partnumberline#1{\@partnumberline#1\@nil}
\def\@partnumberline#1.#2\@nil{\partname\ #1\\*}
\makeatother

\begin{document}

\tableofcontents

\part{title}
\chapter{title}
\end{document}

enter image description here

My opinion is that parts should only be used in very special cases. Maybe yours is, maybe not. Anyway, too much emphasis…

1
  • Your solutions work great, I just can't find a way to center the part Title below "Part 1" (putting \hfill in \def\@partnumberline#1.#2\@nil{#1#2\enspace} doesn't work).
    – user9424
    Commented Jun 27, 2016 at 1:41

You must log in to answer this question.