Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente Prochaine révision Les deux révisions suivantes | ||
3_composition:texte:pages:empecher_un_saut_de_page_entre_deux_lignes [2018/05/24 22:06] joseph.wright |
3_composition:texte:pages:empecher_un_saut_de_page_entre_deux_lignes [2018/12/03 23:46] jejust |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | --- | + | ====== Preventing page breaks between lines ====== |
- | section: Adjusting the typesetting | + | |
- | subsection: Page layout | + | |
- | permalink: / | + | |
- | date: 2014-06-10 | + | |
- | --- | + | |
- | # Preventing page breaks between lines | ||
One commonly requires that a block of typeset material be kept on the | One commonly requires that a block of typeset material be kept on the | ||
same page; it turns out to be surprisingly tricky to arrange this. | same page; it turns out to be surprisingly tricky to arrange this. | ||
- | LaTeX provides a `samepage` environment which claims it | + | LaTeX provides a '' |
does this sort of thing for you. It proceeds by setting infinite | does this sort of thing for you. It proceeds by setting infinite | ||
- | penalties for all sorts of page-break situations; but in many | + | penalties for all sorts of page break situations; but in many |
situations where you want to prevent a page break, | situations where you want to prevent a page break, | ||
- | `samepage` doesn' | + | '' |
text together, you need to end the paragraph inside the environment | text together, you need to end the paragraph inside the environment | ||
- | (see [preserving paragraph parameters](FAQ-paraparam.md)). | + | (see [[FAQ-paraparam|preserving paragraph parameters]]). |
Also, if the things you are trying to keep together insert their own | Also, if the things you are trying to keep together insert their own | ||
- | pagebreak | + | page break hints, |
- | list items' attempts& | + | list items' attempts |
- | are subverted by `samepage`). Naturally, if | + | are subverted by '' |
- | `samepage` _does_ | + | '' |
stuff jutting out at the bottom of the page. | stuff jutting out at the bottom of the page. | ||
Another convenient trick is to set all the relevant stuff in a | Another convenient trick is to set all the relevant stuff in a | ||
- | `\parbox` (or a `minipage` if it contains things like | + | '' |
- | verbatim text that may not be used in the argument of a `\parbox`). | + | verbatim text that may not be used in the argument of a '' |
- | The resulting box certainly | + | The resulting box certainly |
that's not to say that it will actually do what you want it to do: | that's not to say that it will actually do what you want it to do: | ||
again, the box may be left jutting out at the bottom of the page. | again, the box may be left jutting out at the bottom of the page. | ||
- | Why do neither of these obvious things work?& | + | Why do neither of these obvious things work? --- Because TeX can't |
really distinguish between infinitely awful things. | really distinguish between infinitely awful things. | ||
- | `Samepage` will make any possible break point '' | + | '' |
- | bad'' | + | " |
alternative is the leave an infinitely bad few centimetres of blank | alternative is the leave an infinitely bad few centimetres of blank | ||
paper at the bottom of the page, TeX will take the line of least | paper at the bottom of the page, TeX will take the line of least | ||
resistance and do nothing. | resistance and do nothing. | ||
- | This problem still arises even if you have `\raggedbottom` in | + | This problem still arises even if you have '' |
- | effect: TeX doesn' | + | effect: TeX doesn' |
actually shipping a page out. One approach is to set: | actually shipping a page out. One approach is to set: | ||
- | ```latex | + | |
+ | < | ||
\raggedbottom | \raggedbottom | ||
\addtolength{\topskip}{0pt plus 10pt} | \addtolength{\topskip}{0pt plus 10pt} | ||
- | ``` | + | </ |
- | The `10pt` offers a hint to the output routine that the column is | + | The '' |
stretchable; | stretchable; | ||
stretch while building the page. If you're doing this as a temporary | stretch while building the page. If you're doing this as a temporary | ||
- | measure, cancel the change to `\topskip` by: | + | measure, cancel the change to '' |
- | ```latex | + | |
+ | < | ||
\addtolength{\topskip}{0pt plus-10pt} | \addtolength{\topskip}{0pt plus-10pt} | ||
- | ``` | + | </ |
- | as well as resetting | + | as well as resetting |
actually shows up, because it is overwhelmed when the page is shipped | actually shows up, because it is overwhelmed when the page is shipped | ||
- | out by the stretchability introduced by `\raggedbottom`; however, it | + | out by the stretchability introduced by '' |
- | could well have an effect if `\flushbottom` was in effect.) | + | could well have an effect if '' |
An alternative (which derives from a suggestion by Knuth in the | An alternative (which derives from a suggestion by Knuth in the | ||
- | TeXbook) is the package [`needspace`](https:// | + | TeXbook) is the package [[ctanpkg> |
- | which both define a command | + | which both define a command |
what space is needed. | what space is needed. | ||
is cleared, and the matter that needs to be kept together will be | is cleared, and the matter that needs to be kept together will be | ||
- | inserted on the new page. For example, if 4 lines of text need to be | + | inserted on the new page. For example, if 4 lines of text need to be |
kept together, the sequence | kept together, the sequence | ||
- | ```latex | + | |
+ | < | ||
\par | \par | ||
\needspace{4\baselineskip} | \needspace{4\baselineskip} | ||
Ligne 72: | Ligne 69: | ||
<text generating lines 1-4> | <text generating lines 1-4> | ||
% now stuff we don't mind about | % now stuff we don't mind about | ||
- | ``` | + | </ |
Yet another trick by Knuth is useful if you have a sequence of small | Yet another trick by Knuth is useful if you have a sequence of small | ||
blocks of text that need, individually, | blocks of text that need, individually, | ||
- | Insert the command | + | Insert the command |
effect is achieved. | effect is achieved. | ||
- | sequences of LaTeX-style sections, by incorporating | + | sequences of LaTeX-style sections, by incorporating |
- | into the definition of a command (as in | + | into the definition of a command (as in |
- | [patching commands](FAQ-patch.md)). A simple and effective | + | [[FAQ-patch|patching commands]]). A simple and effective |
patch would be: | patch would be: | ||
- | <!-- {% raw %} --> | + | |
- | ```latex | + | |
+ | < | ||
\let\oldsubsubsection=\subsubsection | \let\oldsubsubsection=\subsubsection | ||
\renewcommand{\subsubsection}{% | \renewcommand{\subsubsection}{% | ||
Ligne 88: | Ligne 86: | ||
\oldsubsubsection | \oldsubsubsection | ||
} | } | ||
- | ``` | + | </code> |
- | <!-- {% endraw %} --> | + | |
While the trick works for consecutive sequences of blocks, it's | While the trick works for consecutive sequences of blocks, it's | ||
slightly tricky to get out of such sequences unless the sequence is | slightly tricky to get out of such sequences unless the sequence is | ||
- | interrupted by a forced page break (such as `\clearpage`, which may | + | interrupted by a forced page break (such as '' |
- | be introduced by a `\chapter` command, or the end of the document). | + | be introduced by a '' |
If the sequence is not interrupted, | If the sequence is not interrupted, | ||
forced onto a new page, regardless of whether it actually needs it. | forced onto a new page, regardless of whether it actually needs it. | ||
Ligne 104: | Ligne 102: | ||
decide, case by case, how to deal with problems at the last | decide, case by case, how to deal with problems at the last | ||
proof-reading stage. | proof-reading stage. | ||
- | breaking, using either | + | breaking, using either |
- | place a `\nopagebreak` command to suppress unfortunate breaks. | + | place a '' |
Otherwise, you can make small adjustments to the page geometry, using | Otherwise, you can make small adjustments to the page geometry, using | ||
- | `\enlargethispage`. Supposing you have a line or two that stray: | + | '' |
- | issue the command | + | issue the command |
two lines are added to the page you're typesetting. | two lines are added to the page you're typesetting. | ||
looks impossibly awful or entirely acceptable depends on the document | looks impossibly awful or entirely acceptable depends on the document | ||
context, but the command remains a useful item in the armoury. | context, but the command remains a useful item in the armoury. | ||
- | Note that both `\pagebreak` and `\nopagebreak` take an optional | + | Note that both '' |
number argument to adjust how the command is to be interpreted. | number argument to adjust how the command is to be interpreted. | ||
- | `\pagebreak[0]`, the command | + | '' |
- | might be worth doing, whereas | + | might be worth doing, whereas |
- | page break. | + | page break. |
- | while `\nopagebreak[4]` is a demand. | + | while '' |
default value of the optional argument is 4. | default value of the optional argument is 4. | ||
+ | ----- | ||
+ | |||
+ | //Source:// [[faquk> | ||
+ | |||
+ | {{htmlmetatags> | ||
+ | metatag-og: | ||
+ | metatag-og: | ||
+ | }} | ||