Centering part entries in toc using memoir
You can redefine the \@part
command as defined in memoir.cls
; this command in in charge of producing the part entries in the ToC; the redefinition basically consists in introducing two \hfil
s to center the entries:
\documentclass{memoir}
\cftpagenumbersoff{part}
\makeatletter
\long\def\@part[#1]#2{%
\M@gettitle{#1}%
\phantomsection
\ifnum \c@secnumdepth >-2\relax
\refstepcounter{part}%
\addcontentsline{toc}{part}{\hfil\thepart~#1\hfil}%
\mempartinfo{\thepart}{#1}{#2}%
\else
\addcontentsline{toc}{part}{\hfil#1\hfil}%
\mempartinfo{}{#1}{#2}%
\fi
\partmark{#1}%
{\centering
\interlinepenalty \@M
\parskip\z@
\normalfont
\ifnum \c@secnumdepth >-2\relax
\printpartname \partnamenum \printpartnum
\midpartskip
\fi
\printparttitle{#2}\par}%
\@endpart}
\makeatother
\begin{document}
\tableofcontents*
\part{Part A}
\chapter{Chapter a}
\part{Part B}
\chapter{Chapter b}
\end{document}
The above code will center the entries with respect to the text width minus the length \@tocrmarg
(default value of 2.55em
) reserved to typeset the page numbers for other sectional units using some extra space; you can change this, and center the entries with respect to the full text width by adding \hspace*{\@tocrmarg}
just before the first \hfil
s in my example code above.
Hmm, that can be done with much shorter code:
\makeatletter
\renewcommand\partnumberline[1]{\hfil\hspace\@tocrmarg #1~}
\makeatother
(not entirely sure why though, it's late ...)