I created a custom environment for theorems using mdframed package:
\newtheorem{theorem}{Theorem}
\newtheorem{twierdz}[theorem]{Twierdzenie}
\newenvironment{twierdzenie}
{\begin{mdframed}[backgroundcolor=jasnoszary,
outerlinewidth = 0,
leftmargin= 40,%
rightmargin= 20,
skipbelow=0.5\baselineskip,
skipabove=0.5\baselineskip,
leftline=true,
rightline=true,
topline=false,
bottomline=false]\begin{twierdz}}
{\end{twierdz}\end{mdframed}}
then I use it in following way:
\begin{twierdzenie}
If something... and somethong... then following takes place:
some equations....
\end{twierdzenie}
But sometimes this environment is being splitted between two pages. If the theorem is long, it is fine. But sometimes LaTeX is leaving one or two lines of the theorem on previous/next page.
How can I discourage LaTeX in splitting this environment between pages? I would like it to be splitted only if it really have to.
needspacepackage might be helpful. for a few lines on a "next" page, you'd probably need to consider\enlargethispage(to be done only when you're nearing the final run, with no more changes anticipated); some good information here: Squeeze some more lines on the current page. unfortunately, both of these operations are manual, although it may be possible to build\needspaceinto your environment definition. – barbara beeton Jun 27 '13 at 17:46mdframedhas aneedspaceoption that will reserve space at the top of the environment. E.g.needspace=5\baselineskipwill ensure that there are at least 4 lines together. I don't see a corresponding option for the end. – Andrew Swann Jun 28 '13 at 09:45