# Center part title in TOC

i would like to center the part title in the table of contents (TOC) of my thesis. Based on an answer of egreg, i was able to at least modify the space between part number and part title in the TOC.
However, I cannot set this length individually for each \part (i try it in the MWE below, but as can be seen in the result, it does not work).

\documentclass[dottedtoc]{scrreprt}
\usepackage[parts]{classicthesis}
%custom space between number and text in toc: https://tex.stackexchange.com/a/140053/38853
\makeatletter
\def\ttl@tocpart{% %magic code, don't ask
\def\ttl@a{\protect\numberline{\thepart}\@gobble{}}}
\setlength{\cftpartnumwidth}{100px}
\makeatother

\begin{document}
\tableofcontents
\part{P1}
\chapter{Ch1}
\setlength{\cftpartnumwidth}{150px}
\part{P2}
\chapter{Ch2}
\end{document}


Result:

Other solutions are welcome as well!
(I am aware of https://tex.stackexchange.com/a/210676/38853, however, I don't see how to put the part number on the left and the page number on the right, as in the picture)

• You have to write the setting of the length to the toc-file. – Johannes_B Apr 16 '15 at 13:17
• @Johannes_B, this (combined with tex.stackexchange.com/q/47194) answers my question, thank you! Is there also a possibility to center the part titles (in TOC) automatically? – fabianfuchs Apr 16 '15 at 14:06
• I am not a titletoc user, so i don't know. Using titletoc with KOMA-script is discouraged by the way, as is using titlesec. Please, ask that as a new question to better sort our archive. If you make the question independent of using classicthesis, even better. More possible solutions for others to find. – Johannes_B Apr 16 '15 at 14:11
• You can self-answer this one right here. Closing as duplicate is hard in that case. – Johannes_B Apr 16 '15 at 14:12

## 1 Answer

Based on Johannes_B's comments my hacky solution can be completed:

\documentclass[dottedtoc]{scrreprt}
\usepackage[parts]{classicthesis}
%custom space between number and text in toc: http://tex.stackexchange.com/a/140053/38853
\makeatletter
\def\ttl@tocpart{% %magic code, don't ask
\def\ttl@a{\protect\numberline{\thepart}\@gobble{}}}
\setlength{\cftpartnumwidth}{100px}
\makeatother

\begin{document}
\tableofcontents
\part{P1}
\chapter{Ch1}
\addtocontents{toc}{\protect\setlength{\cftpartnumwidth}{150px}}
\part{P2}
\chapter{Ch2}
\end{document}


yields

Still, more comfortable solutions for centering the title are welcome. :)