24

Following minimal document:

\documentclass{report}

\begin{document}
\renewcommand*\thechapter{\Roman{chapter}}
\tableofcontents
\setcounter{chapter}{6} % Problem starts at chapter 7
\chapter{Seven}
\chapter{Eight}
\section{Eight-one}
\section{Eight-two}
\end{document}

yields this output (cut to size for your convenience):

screenshot

Clearly, the chapter (and section) headings hang into the chapter (section) numbers. For the previous chapter numbers, this isn’t a problem since all chapter titles are aligned to the same column and the numbers I–VI are sufficiently narrow.

(The same happens regardless of document type, I’m actually using scrreprt with the same result.)

How can I prevent this?

  • 1
    For which class do you need a fix? A solution for scrreprt may be easier. A solution for report doesn't necessarily have to be the best for scrreprt. – Stefan Kottwitz Dec 19 '10 at 17:38
  • @Stefan: someone once told me to always use standard classes for MWEs. I’m actually using screprt. I didn’t find a solution in the KOMA documentation, though. – Konrad Rudolph Dec 19 '10 at 18:02
  • if the problem is not depending on class features, a standard class MWE is fine. Here I just prefer a tiny class adjustment over a general package which is 1110 lines long and replaces many class macros, besides the TOC also for lists of tables and contents. – Stefan Kottwitz Dec 19 '10 at 18:21
16

You could also use the tocstyle package, part of KOMA-script:

\documentclass[pagesize]{scrreprt}
\usepackage[tocindentauto]{tocstyle}
\usetocstyle{KOMAlike} %the previous line resets it
\begin{document}
\renewcommand*{\thechapter}{\Roman{chapter}}
\tableofcontents
\setcounter{chapter}{6} % Problem starts at chapter 7
\chapter{Seven}
\chapter{Eight}
\section{Eight-one}
\section{Eight-two}
\end{document}

(compile twice)

  • 1
    Of all the solutions here, this one probably plays nicest with KOMA. Oddly enough, it also resets the TOC style to “normal” so that the style explicitly needs to be reset to KOMA-like. – Konrad Rudolph Dec 19 '10 at 19:11
10

For the record, I ended up using the tocloft package, as follows

\usepackage[titles]{tocloft}

(Option titles since all I want from the package is manipulate the space of the table of content lines; the title should still be rendered using the standard LaTeX method).

\renewcommand*\cftchapnumwidth{2em}
\renewcommand*\cftsecnumwidth{3em}

That said, it’s perhaps more appropriate to change the display of the contents lines so that only the section number is displayed for sections, not the whole “chapter.section” number.

  • Wow! This is such a simple solution for a problem that tends to make your ToC really ugly when using roman numerals. Thank you @konrad-rudolph for adding it here! It saved a ton of hassle for me! Cheers! – Amar Sep 27 '16 at 23:38
8

tocloft works fine with standard classes. If I use KOMA classes, such as the mentioned scrreprt, I don't like tocloft to redefine class macros. For example, features such as koma fonts and the auto end dot are would be lost.

I would make a small modification myself, so I know that few is changed:

\makeatletter
\renewcommand*{\raggedchapterentry}{\setlength\@tempdima{2.3em}}
\renewcommand*\l@section{\bprot@dottedtocline{1}{1.5em}{3.2em}}
\makeatother

alt text

  • 2
    I’m extremely wary of such low-level modifications since they (1) require an intimate knowledge of the classes that surpasses the documented features by far, and (2) is extremely fragile, i.e. not future-proof. Any minor change in the scrreprt class may break this code. This is also the reason why I usually abhor the concept of these super classes like KOMA and memoir (and, indeed, ConTeXt). A modular approach (as implemented by packages) is technically much more sound. Put differently, this problem showcases everything that’s wrong with the “architecture” of TeX. :-( – Konrad Rudolph Dec 19 '10 at 18:46
  • 2
    (That said, I’m grateful for the answer and I’ll probably use it.) – Konrad Rudolph Dec 19 '10 at 18:47
  • 1
    Please do not redefine \l@section this way with newer versions of KOMA-Script. – Schweinebacke Apr 3 '17 at 9:48
8

Since KOMA-Script version 3.20 there are options to change the style of the TOC or list entries. You can use

\RedeclareSectionCommands[tocdynnumwidth]{chapter,section}

to get

enter image description here

or

\RedeclareSectionCommand[tocnumwidth=2.3em]{chapter}
\RedeclareSectionCommand[tocindent=2.3em,tocnumwidth=3.2em]{section}

enter image description here

Code:

\documentclass{scrreprt}[2016/05/10]% needs version 3.20 or newer
\RedeclareSectionCommand[tocnumwidth=2.3em]{chapter}
\RedeclareSectionCommand[tocindent=2.3em,tocnumwidth=3.2em]{section}
\renewcommand*\thechapter{\Roman{chapter}}

\begin{document}
\tableofcontents
\setcounter{chapter}{6} % Problem starts at chapter 7
\chapter{Seven}
\chapter{Eight}
\section{Eight-one}
\section{Eight-two}
\end{document}

It is also possible to use package tocbasic (which is part of the KOMA-Script bundle) with a standard class. Then you can use

\usepackage{tocbasic}[2017/01/03]% needs version 3.22
\DeclareTOCStyleEntry[dynnumwidth]{tocline}{chapter}
\DeclareTOCStyleEntry[dynnumwidth]{tocline}{section}

enter image description here

or

\usepackage{tocbasic}[2016/05/10]
\DeclareTOCStyleEntry[numwidth=2.6em]{tocline}{chapter}
\DeclareTOCStyleEntry[indent=2.6em,numwidth=3.2em]{tocline}{section}

enter image description here

Code:

\documentclass{report}
\renewcommand*\thechapter{\Roman{chapter}}

\usepackage{tocbasic}[2016/05/10]
\DeclareTOCStyleEntry[numwidth=2.6em]{tocline}{chapter}
\DeclareTOCStyleEntry[indent=2.6em,numwidth=3.2em]{tocline}{section}

\begin{document}

\tableofcontents
\setcounter{chapter}{6} % Problem starts at chapter 7
\chapter{Seven}
\chapter{Eight}
\section{Eight-one}
\section{Eight-two}
\end{document}
5

I'll provide an example of the use of titletoc for this problem. It requires loading the eqparbox package to have an automatic alignment of chapter titles, section titles, &c.:

\documentclass{report}
\usepackage[showframe, nomarginpar]{geometry} 
% Font Style
\usepackage{eqparbox}
\usepackage{titletoc}

\titlecontents{chapter}[0em]{\vspace{.25\baselineskip}}
{\eqparbox{ch}{\bfseries\thecontentslabel}\enspace}{}
{\hspace{.5em}\hfill\contentspage}

\titlecontents{section}[0em]{\vspace{.25\baselineskip}}
{\hskip\eqboxwidth{ch}{}\enspace\eqparbox{sec}{\thecontentslabel}\enspace}{}
{\hspace{.5em}\titlerule*[10pt]{$\cdot$}\contentspage}

\begin{document}

\renewcommand*\thechapter{\Roman{chapter}}
\tableofcontents
\setcounter{chapter}{6} % Problem starts at chapter 7
\chapter{Seven}
\chapter{Eight}
\section{Eight-one} \thesection\setcounter{section}{99}
\section{Eight-hundred}

\end{document} 

enter image description here

2

http://projekte.dante.de/DanteFAQ/Verzeichnisse#3

or look for packages like titletoc

  • 1
    Wow. The titletoc documentation is really, really bad and I ended up using the (somewhat simpler, or at least more readably documented) tocloft package. – Konrad Rudolph Dec 19 '10 at 17:51
  • 1
    it is easy to say that a documentation is bad ... but it is really difficult to write a good one ;-) – user2478 Dec 19 '10 at 18:55
  • 2
    true. But by that reasoning one can stifle all criticism – not really fair, is it? – Konrad Rudolph Dec 19 '10 at 18:58
1

I encountered the same problem today and I found that there is an easy solution for me without changing the font of the section title (like what KOMAlike tocstyle does).

\documentclass[pagesize]{scrreprt}
\usepackage{tocstyle}
\usetocstyle{standard}
\begin{document}
\renewcommand*{\thechapter}{\Roman{chapter}}
....
\end{document}

There are other predefined tocstyle you can choose if you would like to explore more options(See tocstyle manual). Hope this would be helpful for future readers.

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.