[Tex/LaTex] How to increase the numwidth for a part in ToC

koma-scriptpartstable of contents

I am using a Koma-Script Book and I would like to begin the part numbers from 2012. However, 4 digit part number entries are causing a problem in the tableofcontents. There is a hbox overfull and the last digit of 2012 is overlapping with the first one or two characters of the part heading. I am using the command \tableofcontents to generate the ToC.

What is a good way to fix this?

Best Answer

Using the tocloft package, you can redefine \cftpartnumwidth:

\documentclass{scrbook}
\usepackage{tocloft}

\renewcommand\cftpartnumwidth{2cm}

\begin{document}

\tableofcontents

\setcounter{part}{2011}
\part{Test Part}

\end{document}

enter image description here

Another option, not requiring additional packages is to redefine \l@part as defined in scrbook.cls; here's such a possible redefinition:

\documentclass{scrbook}

\makeatletter
\renewcommand*\l@part[2]{%
  \ifnum \c@tocdepth >-2\relax
    \addpenalty{-\@highpenalty}%
    \addvspace{2.25em \@plus\p@}%
    \setlength{\@tempdima}{2cm}% original value: 2em
    \if@tocleft
      \ifx\toc@l@number\@empty\else
        \setlength\@tempdima{0\toc@l@number}%
      \fi
    \fi
    \begingroup
      \parindent \z@ \rightskip \@pnumwidth
      \parfillskip -\@pnumwidth
      \leavevmode
      \advance\leftskip\@tempdima
      \hskip -\leftskip
      \usekomafont{partentry}{#1\nobreak
        \usekomafont{partentrypagenumber}{\hfil\nobreak
          \hb@xt@\@pnumwidth{\hss#2}}}\par
      \ifnum \scr@compatibility>\@nameuse{scr@v@2.96}\relax
      \endgroup
      \penalty20010
      \else
          \penalty\@highpenalty
      \endgroup
    \fi
  \fi
}
\makeatother

\begin{document}

\tableofcontents

\setcounter{part}{2011}
\part{Test Part}

\end{document}