views:

234

answers:

2

How do I encourage/make Latex typeset some portion of text so that it will all appear on a consecutive even-page, odd-page pair of pages?

With trial and error, \nopagebreak can be coaxed into doing this, but is there a strategy that Just Works? Something like a samepage environment would be ideal, but one that:

  1. Will force a pagebreak on odd pages if that is needed to get all the text on facing pages;
  2. Allows up to one page break anywhere in the environment body, and fails noisily if that can't be ensured.
+3  A: 

There is a distinction between \clearpage and \cleardoublepage. By using \cleardoublepage just before the stuff you want on the left hand side and \clearpage before the stuff you want on the right hand side you can force the layout you're looking for.

Of course, the twoside option is must.

dmckee
Technically, yes, this answers the question I've asked, but I'm actually after something analogous to samepage: I don't want any breaks unless they are needed to keep the text on the facing pages. Your suggestion will ensure the text is on facing pages, but it's pretty eager to make page breaks.
Charles Stewart
+3  A: 

You could put together an environment such as

\newenvironment{twopage}{%
  \begingroup\setbox0\vbox\bgroup
}{%
  \egroup
  \ifdim\ht0>\textheight
    \setbox1\vsplit0 to \textheight
    \cleardoublepage\unvbox1\clearpage
    \ifdim\ht0>\textheight
      \PackageWarning{twopage}{Overflow in twopage environment}%
    \fi
    \unvbox0\clearpage
  \else
    \clearpage\unvbox0\clearpage
  \fi\endgroup
}

If you want a noisier failure, change \PackageWarning into \PackageError, The \unvboxes should allow for notes/floats to work properly - if you don't need that, you might consider changing them all to \boxes instead (although I'm a bit rusty on the behavior of \vsplit with respect to box depths and skips, so that might produce funny behavior, but it would guarantee that you only took two pages by flowing anything extra off the bottom of the second page).

Steve
Accepted: This seems to be perfect. Am I right that the point of the \unvbox is to stop spurious space, because otherwise \vsplit would make sure box 1 was exactly \textheight high?
Charles Stewart
The `\unvbox` has two main effects, both of which have to do weith making it behave as if there were no enclosing environment. The first is that any whatsits/`\vadjust`s (used by `\mark`, `\footnote`, `\marginpar`, etc) don't work properly inside boxes, since they want to be "top-level" in the shipped-out page (the boxes aren't recursed). The other has to do with space - I don't recall off-hand `\vsplit`'s behavior, but I believe there is a difference between `foo\par\vbox{bar\par baz}\par qux` and `foo\par bar\par baz\par qux`, and it seemed to me that we wanted the latter.
Steve