Document Classes\tableofcontents in book class space issue

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

\tableofcontents in book class space issue

Post by 4fingers »

Hi,

I am currently using the Book.cls to create my table of contents but after adjusting a few things I see that the section number is overlapping into the title. I have uploaded an image so you can see for youself.

Does anyone have any idea where the latex is that controls the spacing bettween the section number and the tile?

Thanks
Attachments
TitleMerge.jpg
TitleMerge.jpg (12.48 KiB) Viewed 7368 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

spiegboy
Posts: 120
Joined: Thu Dec 06, 2007 9:58 am

\tableofcontents in book class space issue

Post by spiegboy »

use tocloft package, you can play with every possible setting concerning toc.
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

\tableofcontents in book class space issue

Post by 4fingers »

Thanks for the suggestion,
It seems I need this

Code: Select all

\@dottedtocline{seclevel}{indent}{numwidth}
With an exmaple being:

Code: Select all

\newcommand*{\l@section}{\@dottedtocline{1}{1.5em}{2.3em}}
I am fairly new to Latex so when I try and include that line I just get
! LaTeX Error: Command \l@section already defined.
Or name \end... illegal,.
Any ideas what I am doing wrong?

Thanks

EDIT:
I managed to fix it by doing this:

Code: Select all

\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{0em}{3em}}
\makeatother
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\tableofcontents in book class space issue

Post by localghost »

This could have been done much easier.

Code: Select all

\setlength{\cftsecnumwidth}{3em}
Adapt the length if necessary.


Best regards and welcome to the board
Thorsten
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

Re: \tableofcontents in book class space issue

Post by 4fingers »

Thanks for the suggestion but that pushes the page number to the right as well.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\tableofcontents in book class space issue

Post by localghost »

4fingers wrote:Thanks for the suggestion but that pushes the page number to the right as well.
That's an issue I can't comprehend. Consider the following example.

Code: Select all

\documentclass[11pt,a4paper,english]{book}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage{tocloft}
\usepackage{blindtext}

\setlength{\cftsecnumwidth}{3em}

\begin{document}
  \frontmatter
  \tableofcontents
  \mainmatter
  \Blinddocument
\end{document}
Build a minimal working example (MWE) that shows the misbehaviour.
4fingers
Posts: 12
Joined: Fri Jul 03, 2009 11:57 am

Re: \tableofcontents in book class space issue

Post by 4fingers »

Its Ok, as long as my previous method works I dont mind if your suggested method returns different results that you might expect.

One thing I have found is that I really only need to adjust the numwidth on the first table of contents. To save space am I able to detect if I am on the first table of contents, in which case apply a differnt numwidth to all the other table of contents?

THanks
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

\tableofcontents in book class space issue

Post by localghost »

4fingers wrote:Its Ok, as long as my previous method works I dont mind if your suggested method returns different results that you might expect. [...]
As long as my method yields unexpected results in your document, your code is flawed.
Post Reply