7

I have two side document(so I use twoside option) in LaTeX. I need to keep some material (text, pictures...) on one double page. In another words I want to allow page break from odd to even page but I want to prohibit breaks from even to odd page.

I tried to write macro:

\newcommand{\nl}{
\\ \ifodd\c@page
\relax
\else
\nopagebreak
\fi}

and use it instead of \\ (I don't use any other line breaks commands in my document) but it does not work. Thanks for all answers.

EDIT: Thanks but Steves environment does not quite work for me. I tried to put my material into it but it does not cause it to fit on 2 pages, instead it says Overflow in twopage environment.

I will try to formulate exactly what I need to do:

  • Preferable an environment or a macro.
  • If the current page is even it must prevent LaTeX from breaking the page(it may break if it is absolutely impossible to keep the material on even page, but I need it to try hard). This may by done by setting penalty to 20000 or by anything else - please suggest as dirty tricks as you can make up.
  • If the current page is odd then the page break is allowed but not necessary.
  • The code that will make use of this environment or macro will be generated by java program so there is no point in generating errors if the material just can't fit into page or double page. Java have no way to know about LaTeX error.

Thanks for all ideas

migrated from stackoverflow.com Feb 7 '12 at 17:24

This question came from our site for professional and enthusiast programmers.

  • Try the code that Steve posted to a question of mine. – Charles Stewart Apr 8 '10 at 12:13
  • 1
    IIRC, that error message was triggered by having more than two full \textheights in the environment. You say you can't tolerate a LaTeX error, so you need to specify what behavior you want when there's too much material to fit. You say "it may break if it is absolutely impossible" - how do you define that? If I understand correctly, where your requirements differ is that you don't want a break before your twopage material. It sounds to me like a job for the output routine, though that's difficult to deal with. – Steve Apr 10 '10 at 7:47
  • If you started a 1.2\textheight tall twopage at the bottom of the right-hand page, what should happen? Should it give up and allow the page break? Should it do a preemptive break so that it has room on the next page? What tricks did you have in mind to make things fit? Most vertical glue on the page has zero shrinkability, though you could adjust \baselineskip or the other skips to something like \baselineskip=12pt minus 4pt, which is as much squashiness as will still allow readability, right at the beginning of the environment. Shrinking the text retroactively would be near impossible. – Steve Apr 10 '10 at 7:55
  • Correction: It may NEVER break inside environment if on even page(so if the material just don't fit in it has to overfull vbox). "It sounds to me like a job for the output routine, though that's difficult to deal with". Yes it might be. That's what I'm afraid of. But there are some tricks to keep some material on one page(put it in one minipage...) I need to find similar tricks to keep it on double page. – Rasto Apr 10 '10 at 14:53
  • Add: "If you started a 1.2\textheight tall twopage at the bottom of the right-hand page, what should happen?" Try to shorter spaces between lines to fit in \textheight. If that is not possible it should do a preemptive break so that it has room on the next double page(and ideally, allow some text from previous (odd) page to flow to the (even) clear page so it won't be absolutely empty). "Shrinking the text retroactively would be near impossible." - that is not good for me to hear it... – Rasto Apr 10 '10 at 14:59
1
\documentclass[twoside]{report}
\usepackage{lipsum}

\makeatletter
\newenvironment{forcedoublepage}{%
  \begingroup
  \dimen255=\prevdepth
  \setbox0\vbox\bgroup
  \prevdepth=\dimen255
}{%
  \egroup
  \ifodd\c@page\@tempdima\z@\else\@tempdima\pagegoal\fi
  \expandafter\@tempdimb\dimexpr\@tempdima+\ht0+\dp0\relax
  \ifdim\@tempdimb<2\pagegoal\else\clearpage\fi
  \unvbox0
  \endgroup
}
\makeatother

\begin{document}
\lipsum

\begin{forcedoublepage}
  \lipsum
\end{forcedoublepage}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.