# Avoid page break in theorem

I have a theorem which is half of it on another page, as I do for you automatically (without \newpage) get full theorem on the next page?

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{theorem}
\newtheorem{teo}{Teorema}[chapter]

\begin{document}
\lipsum[1-5]

\begin{teo}
\lipsum[1]
\end{teo}

\end{document}


I have the left and I need right automatically (without \newpage).

-

Building on @cmhughes' answer, and therefore technically similar, the etoolbox package provides a means to hook into the start and end of an environment using \AtBeginEnvironment and \AtEndEnvironment. As such, a similar result is obtained (without using the ntheorem package):

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newtheorem{teo}{Teorema}[chapter]
\AtBeginEnvironment{teo}{\begin{minipage}{\textwidth}}
\AtEndEnvironment{teo}{\end{minipage}}

\begin{document}
\lipsum[1-5]

\begin{teo}
\lipsum[1]
\end{teo}

\end{document}


As you see from the input, the theorem package is not needed to reproduce the output. However, this may also just be due to your MWE. I would think, this is probably the best way to answer your question. However...

I'm more curious as to why you would want to do this. For example, you'll notice in the aforementioned example that the paragraph skips are stretched to fill the remainder of the page since the theorem overflows to the following page. This can be avoided by using something like a \newpage. So, in the hypothetical yet likely scenario where you have a very long theorem description, you might want to consider foregoing to flush the entire theorem body over to the next page. In this case I would suggest conditioning on where to break or not, based on the amount of space left on the current page. The needspace package provides \Needspace{<length>} and issues a \break if the remaining open space on the page is less than <length>. You may use it in the following sense:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{needspace}% http://ctan.org/pkg/needspace
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newtheorem{teo}{Teorema}[chapter]
\AtBeginEnvironment{teo}{\Needspace{5\baselineskip}}% \break if fewer than 5\baselineskip is available on page

\begin{document}
\lipsum[1-5]

\newpage
\begin{teo}
\lipsum[1]
\end{teo}

\end{document}


The above code adds \Needspace{5\baselineskip} to the beginning of the teo environment (using \AtBeginEnvironment) which will issue a \break if less than 5\baselineskip is available on the current page. If more than this length is available, no \break will be issued. For this example, it produces the same result. Compare that to the disastrous output generated by

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\newtheorem{teo}{Teorema}[chapter]
\AtBeginEnvironment{teo}{\begin{minipage}{\textwidth}}
\AtEndEnvironment{teo}{\end{minipage}}

\begin{document}
\lipsum[1-2]

\begin{teo}
\lipsum[1-5]
\end{teo}

\end{document}


and you'll understand why.

-
Thank you for help, but how to insert \noident in theorem? –  Regis da Silva Oct 2 '11 at 19:26
@RegisdaSilva: Are you saying that you have multiple paragraphs in your teo environment, and you want them all to have a \noindent indentation? That is, have \parindent set to 0pt? If this is the case, you can just include \setlength{\parindent}{0pt} as part of \AtBeginEnvironment{teo}{...}. My MWE already has this format, hence the question. –  Werner Oct 2 '11 at 19:28
Thank you!!!!!!!!! –  Regis da Silva Oct 2 '11 at 20:33

In your case, one option is to use the ntheorem package which provides the commands \theoremprework and \theorempostwork which allow you to insert commands before and after the definition of the theorem globally.

We can use these commands to wrap a minipage around your theorem, as shown below:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{ntheorem}

\theoremprework{\begin{minipage}{\textwidth}}
\theorempostwork{\end{minipage}}
\newtheorem{teo}{Teorema}[chapter]

\begin{document}
\lipsum[1-5]

\begin{teo}
\lipsum[1]
\end{teo}

\end{document}

-