Document ClassesTable of Contents Page breaks

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
rspringuel
Posts: 19
Joined: Wed Apr 28, 2010 7:16 pm

Table of Contents Page breaks

Post by rspringuel »

I'm trying to modify the way that page breaks are handled within the Table of Contents in my class file. In particular, I'd like to make it impossible for a page break to occur between two lines when the indentation/sectioning level of the second line is greater than that on the first and for it to be far more favorable for a page break to occur when the indentation/sectioning level on the second line is less than that on the first.

I.e. If I were writing out the toc manually, I'd do something like this:

Code: Select all

Chapter 1
\nopagebreak
  Section 1.1
  Section 1.2
  \nopagebreak
    Subsection 1.2.1
    Subsection 1.2.2
    \pagebreak[3]
  Section 1.3
  Section 1.4
  \pagebreak[4]
Chapter 2
Does anyone have suggestions for the most efficient way of doing this? My current thoughts are to create a counter which tracks the level of the most recent sectioning command to add to the TOC and then put some \if statements in either the various sectioning commands or the \@sect command (my class file already redefines this command for other reasons, so making further modifications isn't a huge deal) which checks to see if that counter should be incremented or decremented by the command being called and adding the appropriate page break command to the TOC when it is.

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

Post Reply