40

So I am writing a programming book and I decided to include \sections in the ToC as well (see picture below). The problem I am having is that I have ugliness where \chapter is the last item on the page and only on the next page I have the \sections for that chapter (see the very end of picture).

How can I fix ToC to move this 3 Text Conversion and Substitution to a new page rather than leaving it hanging on the current page?

I am using memoir class, btw.

wrong2

daleif
  • 54,450

3 Answers3

49

insert before the third chapter:

\addtocontents{toc}{\protect\newpage}
  • 1
    I have a document with 9 chapters and almost 200 pages. I do not know why, but I have to add this line between chapters 5 and 6 in oder to obtain a page break in the ToC between chapters 6 and 7 (adding this right before \chapter{...} of chapter 7 adds the page break between 7 and 8, not between 6 and 7). – Jan-Philip Gehrcke Aug 25 '14 at 18:02
10

Another solution is to introduce stretchability to the space above chapters in the TOC, something like

\setlength{\cftbeforechapterskip}{1.0em plus 0.3em minus 0.1em}

That is what I normally do.

tilo
  • 103
daleif
  • 54,450
  • 1
    Shouldn't that be \cftbeforechapskip? – twsh Aug 27 '12 at 20:51
  • if you are using tocloft yes, I usually use memoir, where it is renamed \cftbeforechapterskip – daleif Aug 28 '12 at 21:24
  • 1
    In such case you should mention that in your answer - or even better write about both possibilities. For me (using Koma-Script) the suggestion of @Tom worked while yours gave a compile error... – mozzbozz Feb 13 '17 at 06:05
  • @mozzbozz the OP mentions the use of the memoir class, so a memoir answer is appropriate here. It does not make sense to also list, BTW if our are using this and this class do something else. – daleif Feb 13 '17 at 06:08
  • Oh sorry, I must have read over it... Came from Google, and directely scrolled down to the answers - just skimmed through the question quickley (too quick). But what do you mean by it's doing something else? Sorry, I've just started with latex a few days ago and I'm still at a point where I use "trial and error" and it worked for me... – mozzbozz Feb 13 '17 at 07:23
  • 1
    @mozzbozz memoir has the functionality from tocloft build in (though slightly renamed), other classes does not. I would expect that the KOMA classes has something similar. Not all classes offer the same functionality – daleif Feb 13 '17 at 07:52
8

I found this question because I had the same issue. The response by @daleif didn't fix it for me, but I found this to work instead:

\renewcommand{\cftchapterbreak}{\addpenalty{-4000}}

The number you choose in place of 4000 determines how likely the new page will be before a chapter in the ToC. Out of curiosity, I set it to 10000 and all of my ToC chapters disappeared. High values (but under 10000) will prevent any chapter from crossing the page in the ToC. The might be problematic if you have numerous entries below a chapter that require a page break - I have not tested that yet.

DocBuckets
  • 1,041