Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm in a really bad situation with my ToC in the book that I write. Everything is fine until the 9th chapter. There's the "9", some space and then the name of the chapter. But on the 10th (or more) chapter, the "1" of the "10" is under the "9". So the "0" of the "10" is where there should be a space. As a result, there is no space between the number of the chapter and the name of the chapter.

I expected that LaTeX would deal with it as it does with the bibliography entries. It leaves some space empty on the start of one digit numbers so they will be all aligned at the end. (For example, when we have [9] and [10], the 0 is under the 9)

Let me show you my preamble as well

\documentclass[12pt,a4paper]{book}
\usepackage[english, greek]{babel}
\usepackage[iso-8859-7]{inputenc}
\usepackage{kerkis}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{units}
\usepackage{array}
\usepackage{framed}
\usepackage{extarrows}
\usepackage[makeroom,Smaller]{cancel}
\usepackage[pdftex]{graphicx}
\usepackage[top=3.2cm, bottom=2.8cm, left=2.9cm, right=2.9cm,headsep=9mm]{geometry}
\usepackage[Bjornstrup]{fncychap}
\usepackage{fancybox}
\usepackage{fancyhdr}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{footmisc}
\usepackage{subfiles}
\usepackage{float}
\usepackage{slashbox}
\usepackage[official]{eurosym}

(Here there are some commands but they've got nothing to do with that)

\begin {document}
\frontmatter
\tableofcontents
\newpage
\thispagestyle{empty}
\mbox{}
\newpage


\mainmatter
.
.
.
share|improve this question
3  
Instead of including all the packages in your preamble, it's better when asking for help to construct the smallest complete document that shows the problem you are having. The one lockstep created in his answer is a good example of what a minimal example for your problem would look like. –  Alan Munn May 12 '11 at 22:42
add comment

1 Answer

Use the tocloft package. Page 11 of its documentation describes how to set chapter resp. section numbers flushright.

\documentclass{book}

\usepackage{tocloft}
\newlength{\mylength}
\setlength{\mylength}{0.7em}
\renewcommand{\cftchappresnum}{\hfill}
\renewcommand{\cftchapaftersnum}{\hspace*{\mylength}}
\addtolength{\cftchapnumwidth}{\mylength}
\addtolength{\cftsecindent}{\mylength}
\addtolength{\cftsubsecindent}{\mylength}

\begin{document}

\tableofcontents

% The following code line is added to make the example truly minimal
\setcounter{chapter}{8} 

\chapter{Nine}

\chapter{Ten}

\section{Ten.One}

\subsection{Ten.One.One}

\end{document}
share|improve this answer
    
For some reason it's not working on me. There's an error saying Command \mylen already defined. But there's no other command like that in my preamble. It works when I change the name to \myleng. But the sections don't look so well now –  Alex May 12 '11 at 22:04
    
@Alex: I updated my example. –  lockstep May 12 '11 at 22:18
    
Wow it works very nice now. The only problem is the gap between 9.1 SectionName and the 10.1 SectionName. On the subsection the same. In the case of 9.1 the gap is normal but in the 10.1 is a bit too small but that's alright if you can't fix that. I'm happy as it is now, although I would be happier if you could fix it (pleaseeeeeeeeee...) –  Alex May 12 '11 at 22:27
    
@Alex: I updated again -- please check. Also, I'm afraid that the width of the box containing the section number can only be set once, i.e. the gap must become smaller if the section number becomes wider (10.1.1 instead of 9.1.1). –  lockstep May 12 '11 at 22:34
2  
@Alex You could also take a look at the tocloft documentation, now that lockstep has got you started. You can increase the space of the section numbers by adding \setlength{\cftsecnumwidth}{2.5em} to your preamble, and adjust the width as needed. Since the numbers are being set flush left, the space between the longer section numbers and the shorter ones will always be slightly different. You could use the same technique as in lockstep's code to set them flush right, but I don't recommend it. –  Alan Munn May 12 '11 at 22:41
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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