# How to center part entries in toc with memoir?

I'm typesetting a book with memoir class and in this book the parts have to be centred in the table of contents (TOC). Thanks to Center parts in toc with tocloft I got this working as long as the part name isn't longer than one line. But if it is longer, the second line is not centred. Here is a working example:

\documentclass[a4paper,10pt,twoside]{memoir}

\usepackage{polyglossia}
\usepackage{blindtext}
\usepackage{fontspec}

\makeatletter
\renewcommand{\partnumberline}[1]{\hfil\hspace\@tocrmarg Teil #1:~}
\makeatother
\renewcommand{\cftpartfont}{\large\normalfont}
\cftpagenumbersoff{part}

\begin{document}
\tableofcontents*
\part{It works with one liners}
\chapter{Test}
\Blindtext
\section{Test124}
\Blindtext
\part{But it does not work with those: That is only a test nothing more, please do not read it}
\chapter{Test2}
\Blindtext \Blindtext \Blindtext
\end{document}


What could I do to get all lines centred?

## 1 Answer

The easiest solution might be to not use the memoir interface at all!

Instead go straight to the source and recode it. Here I have removed all the code that normally makes space for the page number and the left indentation etc.

\makeatletter
\renewcommand{\partnumberline}[1]{Teil #1:~}
\renewcommand*{\l@part}[2]{%
\ifnum \c@tocdepth >-2\relax
\cftpartbreak
\begingroup
{
\setlength{\memRTLleftskip}{0pt}
\setlength{\memRTLrightskip}{0pt}
\interlinepenalty\@M
\centering
\cftpartfont #1
\par
}
\nobreak
\global\@nobreaktrue
\everypar{\global\@nobreakfalse\everypar{}}%
\endgroup
\fi}
\makeatother
\renewcommand{\cftpartfont}{\large\normalfont}