Keeps, Orphans, and Widows
- To keep lines of text together.
- To manage orphans and widows.
Keep Constraints
Often you will want to make sure that certain content is kept together. For example, a paragraph following a heading should stay with that heading. This type of thing is handled with the keep attributes described below.
keep-with-previous and keep-with-next
The keep-with-previous attribute instructs the processor to try to keep an FO on the same page, column and line as the previous FO. Similarly, the keep-with-next attribute instructs the processor to try to keep an FO on the same page, column and line as the following FO. You can be more specific by appending .within-line, .within-column, or .within-page to the attribute (e.g, keep-with-next.within-page). Possible values for these attributes are shown below:
- An integer (e.g, 10) - specifies the strength of the constraint, so that the processor knows how to handle conflicting constraints. The higher the number, the stronger the constraint.
- always - specifies a strength value of infinity (e.g., greater than any integer).
<fo:block font-weight="bold" keep-with-next="always"> Header </fo:block> <fo:block> Body </fo:block>
keep-together
The keep-together attribute is used to keep chunks of content together.
<fo:block keep-together="always"> <fo:block font-weight="bold"> Header </fo:block> <fo:block> Body </fo:block> </fo:block>
Note that breaks take precedence over keeps.
Orphans and Widows
Orphans are lines of text left at the end of a page. Widows are lines of text that carry over to the next page. The orphans and widows attributes are used to enforce a minimum number of orphans and widows in a block. For example, the code below specifies that the content should have no fewer than three orphans and three widows.
<fo:block widows="3" orphans="3"> Content </fo:block>
Keeps, Orphans, and Widows Conclusion
In this lesson of the XSL-FO tutorial, you have learned how to keep content together with keep FOs and the orphans and widows attributes.
