When I use \tableofcontents I get all my contents in a single page except for a line that goes on the other page, how can I make all in the same page?

-
I have the same problem for another reason: the page next to the ToC is text only (plus one line of ToC), the page after that starts with a section title. The last line of ToC seems to be forced here by LaTeX in order to avoid getting the section title at the bottom: it can put a space between the ToC and the text rather than between paragraphs. –  Benoît Kloeckner Aug 28 '12 at 12:40

Add the following code line in the main text immediately before the chapter/section entry that starts a new ToC page:

\addtocontents{toc}{\protect\enlargethispage{\baselineskip}}


This will enlarge the first ToC page by the value of \baselineskip (i.e. one line), which should make the last ToC entry fit on this page.

EDIT: For top-level-entries (e.g. chapters in books) that add some vertical space before their respective ToC entry, a larger value (say, 2\baselineskip) may be needed.

EDIT 2: I have no satisfying answer why the page number is still positioned the way it is, but a workaround. Ignore my first answer and instead add the following to your preamble:

\usepackage{etoolbox}
\makeatletter
\patchcmd{\l@chapter}{1.0em}{0.8em}{}{}
\makeatother


This will reduce the vertical space between chapter ToC entries from 1.0em to 0.8em, which hopefully is enough to make your ToC fit on one page.

EDIT 3: And here's a "satisfying" answer for the observed behaviour of my first solution -- quoting from source2e:

\enlargethispage{<dim>} [a]dds <dim> to the height of the current column only. On the printed page the bottom of this column is extended downwards by exactly <dim> without having any effect on the placement of the footer; this may result in an overprinting.

-
I wrote \addtocontents{toc}{\protect \enlargethispage{\baselineskip}} \addcontentsline{toc}{chapter}{Bibliography} but it remains always with a line in the second page where it's written Bibliography. –  Peter E Jul 18 '11 at 17:43
@Peter: As I wrote in my edited answer, try a larger value (e.g. 2\baselineskip). –  lockstep Jul 18 '11 at 17:45
It worked but now I have: Bibliographi 1 124 where 1 is the number of the page of the table of contents. How can I fix this? –  Peter E Jul 18 '11 at 17:50

{\small\tableofcontents}


Or if some of your contents entries have long names and break onto a second line, you could give them a shorter optional name that appears in the contents:

\section[short name]{The longer name that appears only where the section heading goes}


There is also the option to try and make your contents be two columned. Several packages do this (e.g. biblatex's documentation is like this) but I can't remember how to do this.

-
If I use {\small\tableofcontents} it remains the same, always with a line in the second page –  Peter E Jul 18 '11 at 17:34
I find it very wrong to change the font size of the toc. I think it is ok to have e.g. the captions in a smaller font, but whole pages should look consistent in the document –  Martin H Jul 18 '11 at 17:38
@Marting H I often put my bibliography in a smaller font. I don't think it looks inconsistent... –  Seamus Jul 19 '11 at 11:27

Yet another way to forcibly make ToC fit into one page is to put

\addtocontents{toc}{~\vspace{-3\baselineskip}}


right after the \tableofcontents command. This will reduce the vertical space between the title (i.e. "Contents") and the first entry in ToC by 3\baselineskip, thus making room for the line that was sent to the next page.

It's maybe not elegant, but something will have to give, and this is one more option. The advantage is that you don't reduce the vertical space between the text and the footer, which is in most cases smaller (thus less flexible for changing) than the space between the title and the first entry. Hope it helps!

-