Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}

here

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

share|improve this question

2 Answers 2

up vote 6 down vote accepted

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}

enter image description here

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.

share|improve this answer
    
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

We can follow the answers to this post: Unbreakable block

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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