Sie sind hier

\partname in TOC entry

Hi all,

I'm using the scrbook class for my document. My document is divided into multiple parts. However, the entries for the parts in the Table of Conents only contain the \thepart and not \partname. At the moment the entries look like: "I. Introduction" and "II. Technical Details" while I want them to look like: "Part I. Introduction" and "Part II. Technical Details".

Any help is much appreciated.

Bild von Markus Kohm

If you are using an up-do-date KOMA-Script release, you may simply use

\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
}

Thanks for the reply. Your command kind of works. The problem is that now "Part I" becomes too long and falls on top of the actual part name. So there is something wrong with the length calculation somewhere. I looked at the code for \addtocentrydefault in scrbook.sty and it uses \protect\numberline{} for the part number, which apparently uses a wrong width.

I got it working at the end with the following:

\renewcommand*{\addparttocentry}[2]{%
  \addcontentsline{toc}{part}{\partname\nobreakspace \protect\numberline{#1}#2}%
}

Many thanks for your help.

Bild von Markus Kohm

Without complete, minimal example I'm not able to decide wether the length calculation for \numberline is enabled or not and works or not. By default, there's no length calculation but fix lengths are used (see \l@part). With option toc=flat auto-length-calculation would be used, but maybe this is not a good choice for such part entries.

BTW: Better auto-length-calculation will be available with package tocstyle. See tocstyle.pdf for more information.

Using \partname before \numberline may break features of toc packages or of toc display with KOMA-Script classes. There's no support for this! You're definition may also break part entries without numbers!

Here's a minimal example which illustrates the problem:

\documentclass{scrbook}
\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
}%
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Introduction}
\chapter{Background}
\chapter{Related Work}
\part{Technical Details}
\chapter{Implementation Strategy}
\chapter{Performance Analysis}
\end{document}

I will look into tocstyle. Thanks for the tip.

Bild von Markus Kohm

With this settings you are not using any auto-length-calculation. You may try

\documentclass{scrbook}
\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
}%
\usepackage{tocstyle}
\usetocstyle{KOMAlike}
 
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Introduction}
\chapter{Background}
\chapter{Related Work}
\part{Technical Details}
\chapter{Implementation Strategy}
\chapter{Performance Analysis}
\end{document}

to use the auto-length-calculaton of ALPHA package tocstyle or

\documentclass[toc=flat]{scrbook}
\renewcommand*{\addparttocentry}[2]{%
  \addtocentrydefault{part}{\partname\nobreakspace #1}{#2}%
}%
 
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\part{Introduction}
\chapter{Background}
\chapter{Related Work}
\part{Technical Details}
\chapter{Implementation Strategy}
\chapter{Performance Analysis}
\end{document}

to use the auto-length-calculation of scrbook but with another toc layout.

Or you may change \l@part to manually set up another length for the part number.

Thanks for the explanations.

Comments for "\partname in TOC entry" abonnieren