4

I would like to use the option counterwithin to get my numbering as I, I.1., I.2, .., II, II.1, II.2,...

I use the following minimal script

\documentclass[11pt, a4paper, twoside, openany]{scrbook}
\usepackage{chngcntr}
\counterwithin{chapter}{part}
\begin{document}
\tableofcontents
\part{This is part 1}
\chapter{This is I.1}
\part{This is part 2}
\chapter{This is II.1}
\end{document}

This does what I want, but in the table of content, for some reason, there is not enough space between the numbers and the chapter names. As the roman numbers get longer, the numbers and text even overlap. in table of contenn, spacing between number and text is not correct

2 Answers2

3

You can use tocloft and change the numwidth:

\setlength{\cftchapnumwidth}{2em}

Change 2em to whatever you desire.

\documentclass[11pt, a4paper, twoside, openany]{scrbook}
\usepackage{chngcntr}
\usepackage{tocloft}
\counterwithin{chapter}{part}
\setlength{\cftchapnumwidth}{2em}
\begin{document}
\tableofcontents
\part{This is part 1}
\chapter{This is I.1}
\part{This is part 2}
\chapter{This is II.1}
\end{document}

enter image description here

You can do the same for part, sec subsec, subsubsec para and subpara in a similar fashion. Do

\setlength{\cftXnumwidth}{<dimension>}

Where X has to be replaced by part sec etc.

  • But I would use \counterwithin*{chapter}{part} so that chapter numbers are not prepended by part number. –  May 30 '14 at 11:15
3

Update: It is easy with KOMA-Script version 3.15 or newer. Just use the new command \RedeclareSectionCommand:

\RedeclareSectionCommand[counterwithin=part,tocnumwidth=2em]{chapter}

Note that the package chngcntr is not needed.

enter image description here

Code:

\documentclass[open=any]{scrbook}
\RedeclareSectionCommand[
    counterwithin=part,
    tocnumwidth=2.5em
  ]{chapter}
\begin{document}
\tableofcontents
\part{This is part 1}
\chapter{This is I.1}
\part{This is part 2}
\chapter{This is II.1}
\end{document}

You can use the package tocstyle which is part of the KOMA-Script-bundle.

\documentclass[openany]{scrbook}
\usepackage{tocstyle} 
\usetocstyle{KOMAlike} 
\usepackage{chngcntr}
\usepackage{blindtext}
\counterwithin{chapter}{part}
\begin{document}
\tableofcontents
\part{This is part 1}
\blinddocument\blinddocument
\part{This is part 2}
\blinddocument\blinddocument
\end{document}

You have to run the code several times to get:

enter image description here

Or you can use the option toc=flat:

\documentclass[openany,toc=flat]{scrbook}
\usepackage{chngcntr}
\usepackage{blindtext}
\counterwithin{chapter}{part}
\begin{document}
\tableofcontents
\part{This is part 1}
\blinddocument\blinddocument
\part{This is part 2}
\blinddocument\blinddocument
\end{document}

Run twice to get

enter image description here

esdd
  • 85,675