I have a problem with table of contents. I have changed the numbers of sections, that instead of numbers I have words, lets say "Dodatok A". But now, when the "number" of section is longer, the title of section and the "Dodatok A" are crossing, so it is not readable. Is there any way how to adjust the width of box for the number of section? I put here a picture with a part of table of contents, where you can see the problem. Thank you.

   \usepackage[total={17cm,25cm}, top=2.5cm, bottom=2.5cm, left=3.5cm, right=2cm, includefoot]{geometry}  


    some sections, subsections, figures etc.

      \renewcommand\thesection{Dodatok \Alph{section}}


    \section{Kalibračná symetria pre elektromagnetizmus}
    text text 


A picture of a part of my table of contents, where you can see my problem.

marked as duplicate by Marco Daniel, barbara beeton, Claudio Fiandrino, Gonzalo Medina, Xavier May 9 '13 at 17:42

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • @MarcoDaniel: I would agree. Your answer should be adjusted though to incorporate some difference when using a class like article compared to book and/or report. article.cls defines \l@section differently to that of book.cls and report.cls and therefore requires different treatment. – Werner May 9 '13 at 16:30
  • Suzie, you can drop the use of epsfig as it is deprecated. – Werner May 9 '13 at 16:31
  • @Werner: But only if you don't use any related package. – Marco Daniel May 9 '13 at 16:31

This sort of adjustment is usually left for packages like tocloft. However, a manual adjustment is also possible by inserting content for the adjustment into the ToC at the right time. The use of babel does make things a tad trickier, since babel defines certain language-specific shorthands. These shorthands influence the capability to patch (or modify) commands on the fly. In particular, etoolbox is used to patch \l@section - the macro responsible for setting section-style entries in the ToC - while temporarily turning off the shorthand for -; set active by babel:

enter image description here

\usepackage{calc,etoolbox}% http://ctan.org/pkg/{calc,etoolbox}
\usepackage[slovak]{babel}% http://ctan.org/pkg/babel


\section{A section}

  \protect\shorthandoff{-}% Remove 'active'ness of '-'
  \protect\patchcmd{\protect\l@section}{1.5em}{\widthof{\textbf{Section X\quad}}}{}{}%
  \protect\shorthandon{-}}% Make '-' active again

\section{Another section}


Since \tableofcontents reads content from the .toc file, it's appearance is usually delayed by at least one compilation. To that end, and somewhat counter-intuitive for those unfamiliar with TeX's auxiliary file usage, you need to insert the ToC-related adjustment within your document. The above does this, by inserting a patch to replace to default 1.5em space allowed for the section number with \widthof{\textbf{Section X\quad}} - the new width of section "numbers."

  • Thank you very much. I must be doing something wrong, but it doesn't work. I made this changes in my code: 1. add \usepackage{calc,etoolbox} to the preamble, 2. add \makeatletter \addtocontents{toc}{\protect\patchcmd{\protect\l@section}{1.5em}{\widthof{\textbf{Section X\quad}}}{}{}} \makeatother above the \section{Kalibračná symetria pre elektromagnetizmus} . Is it good? – Suzie May 9 '13 at 17:02
  • @Suzie: Yes, that looks good (just like I did in my MWE). You mention that "it doesn't work". What exactly? Does a compilation produce an error? Is there no change? When you look at <filename>.toc in your working folder, is there anything in there that resembles \patchcmd like inserted above? Are you using any ToC-related packages (I tested it even with hyperref and there's no problem). – Werner May 9 '13 at 17:46
  • @Werner No error, but no changes. I am using only those packages, that are included in my code (I have edited it so now there are all). In the .toc file, there is this: \patchcmd {\l@section }{1.5em}{\widthof {\textbf {Section X\hskip 1em\relax }}}{}{}. – Suzie May 9 '13 at 18:39
  • @Suzie: This must mean that the patch is not working. Change the last two empty arguments {}{} in the \patchcmd to {\protect\typeout{success}}{\protect\typeout{failure}}. This should output success in your .log if the patch was successful and failure otherwise. I see success when I review the .log file. What do you see? – Werner May 9 '13 at 18:53
  • ...moreover, what about using some of the suggestions within How to modify the indentation before sectioning titles in the table of contents? to correct the behaviour? Mine does a direct/manual adjustment. However, you could also use other packages, if this doesn't work for you. – Werner May 9 '13 at 19:07

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