4

I have the following code

\documentclass{scrreprt}
%\usepackage[titles]{tocloft}
%\renewcommand{\cftchappresnum}{\thepart.}

\begin{document}
    \tableofcontents
    \part{First Part}
    \chapter{First Chapter}
\end{document}

that results in the following table of contents: table of contents

How can I include the number of the part into the chapter entry, i.e. get I.1. First Chapter?

As you can see, I tried to use the tocloft package but without success.

5

You have to adjust a number of length, in addition to the counter representation. Here is a minimal example with some adjustments up to the section level:

enter image description here

\documentclass{scrreprt}
\renewcommand{\thechapter}{\thepart.\arabic{chapter}}% Prefix chapter with part number
\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapter}{1.5em}{2em}{}{}% Increase number width for chapter
\renewcommand{\l@section}{\bprot@dottedtocline{1}{2em}{2.7em}}% Increase number width and
                                                              % indent for section
\makeatother
\begin{document}
    \tableofcontents
    \part{First Part}
    \chapter{First Chapter}
    \section{A section}
\end{document}

Prepending the part number to the chapter number is achieved using

\renewcommand{\thechapter}{\thepart.\arabic{chapter}}

This would be a global replacement, making \thepart. appear before a chapter number in the text, the ToC and references to chapters (as well as lower sectional units, since they inherit the hierarchy).

Secondly, we patch \l@chapter (using etoolbox) to allow for a wider spacing around the number. Since the ToC forms a hierarchy of the document structure, a change in one indentation level should typically be followed by an adjustment at lower levels as well. So, since the increase was made from 1.5em to 2em, we need to adjust the <indent> of \l@section (and possibly \l@subsection...) as well:

\renewcommand{\l@section}{\bprot@dottedtocline{1}{2em}{2.7em}}% Increase number width and
                                                              % indent for section

Argument structure of \bprot@dottedtocline{<level>}{<indent>}{<numwidth>} indents a sectional units at level <level> by a length <indent> and puts the number in a box of width <numwidth>. Under scrreprt, the following definitions hold for lower sectional units (if you wish to adjust them as well):

\newcommand*\l@subsection{\bprot@dottedtocline{2}{3.8em}{3.2em}}
\newcommand*\l@subsubsection{\bprot@dottedtocline{3}{7.0em}{4.1em}}
\newcommand*\l@paragraph{\bprot@dottedtocline{4}{10em}{5em}}
\newcommand*\l@subparagraph{\bprot@dottedtocline{5}{12em}{6em}}
  • Changing \thechapter globally is a bit ugly but it works. Thank you for the detailed explaination. – UniQP May 6 '14 at 20:58
  • 1
    @UniQP: You need consistency in your document. If you want I.1 in the ToC and 1 in the rest of your text and references, that can be done, but it then chapter numbering would not be consistent. – Werner May 6 '14 at 21:03
  • Does a similar solution exist for non-KOMA documentclasses? – Reinhard Neuwirth Jun 18 '16 at 6:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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