13

I wanted to try out encouraging of pagebreak using \pagebreak[number].

As far for now it only breaks the page when I define \pagebreak[4] and only then (it won't work on any other circumstances).

Can someone explain to me how should it work ?

If I have a new section just in the bottom of the page and if I use \pagebreak[3] over \section{xxxxx} it will not break it then.

The manual says :

The \pagebreak command tells LaTeX to break the current page at the point of the command. With the optional argument, number, you can convert the \pagebreak command from a demand to a request. The number must be a number from 0 to 4. The higher the number, the more insistent the request is.

3
  • Take a look at this: personal.ceu.hu/tex/breaking.htm#pagebreak
    – azetina
    Jan 12, 2014 at 18:47
  • The idea of \pagebreak is different from what you try to achieve, it cannot work unless you tell LaTeX that bottomsections are wrong. Have you tried \usepackage[nobottomtitles]{titlesec} ?
    – yo'
    Jan 12, 2014 at 18:49
  • @tohecz It kind of helps :) Can you post more details about this option nobottomtitles ?
    – Patryk
    Jan 12, 2014 at 19:09

2 Answers 2

13

The command \pagebreak[3] only modifies the chances that the break appears at that place. Namely, it reduces the penalty for such a break by 301. The command \pagebreak[4] reduces the penalty by 10000 which is a sort-of "TeX's infinity", and it enforces a page break by making it not cost anything.

However, \pagebreak[3] cannot work in cases where LaTeX does not see anything wrong with the output (which is the case of a section title quite close to the bottom of the page). So you have to tell LaTeX to consider bottomtitles as a bad thing, and the easiest way to do this is by using a feature of the titlesec package:

\usepackage[nobottomtitles]{titlesec}

Its idea is simple: Enforce a page-break if there is not much space left on the page. The implementation is more complicated, and I am sure that I am not able to explain in here in a good way.

1
  • Thanks for mentioning nobottomtitles! I didn’t expect such a feature in titlesec.
    – lblb
    Apr 14, 2018 at 9:59
17

A broad knowledge of how page breaking works can help. TeX accumulates material in the main vertical list, mostly lines after having split a paragraph, but also the “glue” it inserts between lines. Other material can be present on this vertical list, for instance the glue inserted before and after sectional titles for vertically spacing them. There are other things, but a complete description would take too long; the other main ingredient for page breaking are penalties.

A penalty can be inserted either automatically (by TeX the program) or manually (usually embedded in macros, so the user doesn't need to be aware of them). An automatic penalty is inserted after the first line of a paragraph (in the amount specified by the parameter \clubpenalty) and after the last but one line (\widowpenalty). A typical manual penalty is inserted by \pagebreak.

Such penalties tell TeX the desirability for a page break at that point (always between lines, because paragraphing has already been performed when TeX looks for a page break point). If the penalty is positive, the break is undesirable, if negative it is desirable; the range is -10000..10000: a –10000 penalty forces a page break, a penalty of 10000 disallows it.

Page breaks can take place at glue or at penalties (not the complete truth, actually, but quite near it). No page break can happen at glue that's immediately preceded by a penalty or other glue, but a penalty is always considered for a page break.

When TeX accumulates material, it keeps track of the cost for breaking a page at every feasible break point. The precise computations of this cost are explained in the TeXbook (chapter 15). A 10000 penalty makes for a “maximum cost” (100000). This cost depends also on the height of the accumulated material, so when the page is still almost empty, the cost will be this maximum value, but when the accumulated material is higher than the space reserved for the page it becomes infinite. The space reserved for the page is contained in the internal parameter \pagegoal that is equal to \textwidth (in LaTeXspeak, \vsize is the primitive parameter) when a new page is started (more precisely, when the first item is appended to the main vertical list after a page has been ejected), but it can decrease if footnotes or floats are found during processing.

The commands

\pagebreak[0] \pagebreak[1] \pagebreak[2] \pagebreak[3] \pagebreak[4]

insert a penalty at the spot. If the command is issued between paragraphs it will be precisely at the spot, if it's issued in a paragraph, the penalty will be inserted just after the line in which it happens to fall, before the interline glue. The amounts are

0 \@lowpenalty \@medpenalty \@highpenalty 10000

(their opposite are inserted by the similar command \nopagebreak). It's the document class that fixes the intermediate values; for the standard classes they are

\@lowpenalty  =  51
\@medpenalty  = 151
\@highpenalty = 301

TeX keeps track of the costs, marking the “best so far” and, when it finds the cost for a page break is infinite, it backs up and splits the page at the most recent “best so far” cost. When a break point is superseded by another “best so far”, the penalties associated to that break (there may be none, of course) are discarded and they'll no more influence the computations.

So, if one issues \pagebreak[3] at a point that's sufficiently far from the next page break, in the sense that more material fits in the page after it, the penalty will be forgotten. Conversely, a \pagebreak[4] (or, equivalently, simply \pagebreak) will produce a cost of –10000 that, by rule, forces a page break, even if the accumulated material is still far from \pagegoal.

The sectional commands of LaTeX take care that the first paragraph started after them is preceded by a 10000 penalty, so no page break can occur between the title and the first paragraph or an immediately following sectional title. The next feasible break point is thus after the second line of the next paragraph (because the macros also temporarily set \clubpenalty to 10000).

This behavior is modifiable, because the current value of \pagegoal and the “height so far” can be examined at any time and the macro responsible for typesetting a section title can decide whether the available space is below some threshold and, in case, issue a \pagebreak command.

The package needspace provides a user interface for deciding whether prematurely breaking a page depending on the available space. The package titlesec, with the nobottomtitles* option does a similar thing (the inserted penalty is, however, 9999 and not 10000).


A final note: the penalties or glue where the page break takes place are moved to the next page, where they will disappear, because TeX always discards these items when it starts building a new page. Some clever output routine can use this fact, performing some actions before the items are discarded. Indeed, the LaTeX output routine does this, in order to accommodate page floats if so it's needed: the penalty issued by \clearpage is –10001, so the output routine can know that the page break has been a consequence of \clearpage and it will flush the float queues.

1
  • 3
    You are really a good teacher of TeX. :-)
    – user11232
    Jan 12, 2014 at 23:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .