TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 5 down vote accepted

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}
share|improve this answer
    
Okay, so tocloft is a package! I read it everywhere and thought it was some another toc method which I did not want to venture into. Let me check and I will get back to you. – Jayesh Badwaik Jul 19 '12 at 5:12
    
Thank You. This works. I should probably wait sometime before accessing the answer though. – Jayesh Badwaik Jul 19 '12 at 5:21

Since you are using KOMA-Script, you could have a look at the package tocstyle.

\usepackage{tocstyle}
\usetocstyle{KOMAlike}

This requires extra compilation runs to calculate the widths of the TOC.

share|improve this answer

The width of the box that contains the part number in the ToC is 2em by default. This width is specified in \l@part. You can patch it using the etoolbox package to your liking:

enter image description here

\documentclass{scrbook}% http://ctan.org/pkg/koma-script
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\makeatletter
\patchcmd{\l@part}% <cmd>
  {2em}% <search>
  {2cm}% <replace>
  {}{}% <success><failure>
\makeatother
\setcounter{part}{2011}% Initialize part counter
\begin{document}
\tableofcontents
\part{First part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\part{Second part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\part{Last part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\end{document}

As usual, the \patchcmd{<cmd>}{<search>}{<replace>}{<success>}{<failure>} command searches for <search> in <cmd> and replaces it with <replace>. Additionally, it executes <success> if the replacement was successful, otherwise it executes <failure>.

share|improve this answer

With a KOMA-Script class there is no additional package needed. You can use

\RedeclareSectionCommand[
  tocnumwidth=2cm
]{part}

to change the space for the part number in TOC to 2cm.

enter image description here

Code:

\documentclass{scrbook}

\RedeclareSectionCommand[
  tocnumwidth=2cm
]{part}

\setcounter{part}{2011}
\begin{document}
\tableofcontents
\part{First part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\part{Second part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\part{Last part}
\chapter{A chapter}\section{A section}
\chapter{A chapter}\section{A section}
\end{document}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.