Widow/Orphan control in PDF
-
echopraxia
- Propeller Head
- Posts: 13
- Joined: Wed Aug 29, 2012 11:38 am
Widow/Orphan control in PDF
I have a page with several tables, and I can't seem to figure out how to link the paragraph above to the table below so that they do not end up on different pages. I can't seem to figure out how to put in a page break, though tables themselves have widow/orphan control on them and are working fine and generating page breaks where appropriate for a table-only. Any help on this would be greatly appreciated. I have multiple audiences with condition tags all over the place so manually formatting this each time I need to generate it is a horrible pain.
Re: Widow/Orphan control in PDF
Unless you take the time to do manual formatting, you're almost always going to have a few bad page breaks in any sufficiently large document. I've learned to just put up with them, since few people actually print my documentation and fewer still would bother to complain.echopraxia wrote:I have a page with several tables, and I can't seem to figure out how to link the paragraph above to the table below so that they do not end up on different pages. I can't seem to figure out how to put in a page break, though tables themselves have widow/orphan control on them and are working fine and generating page breaks where appropriate for a table-only. Any help on this would be greatly appreciated. I have multiple audiences with condition tags all over the place so manually formatting this each time I need to generate it is a horrible pain.
That being said, you can set some sane defaults using CSS (if you haven't already.) There are several relevant properties, and while you can apply them to any element to get the look you want, I generally start with these for any new project:
Code: Select all
@media pdf {
* {
mc-hyphenate: never;
mc-short-line-method: tighten-loosen;
mc-short-line: 4;
}
h1,h2,h3,h4,h5,h6,th,p.TOC1,p.ListItem {
page-break-after: avoid;
}
p,td,ol,ul {
orphans: 3;
widows: 3;
}
li,td {
page-break-inside: avoid;
}
}- Turns off hyphenation
- Reduces the occurrence of lines with very little text
- Avoids page breaks after headings, inside lists, and inside table cells
- Sets widow/orphan control to three lines of text
Give that a try for your starting point. If having any bad page breaks is unacceptable, then you can add the page-break-before, page-break-after, or page-break-inside rules to a special CSS class. Then, add that class manually to problematic table cells, paragraphs, or headings to fix things up.