[Tex/LaTex] Keep theorem content on the same page

amsthmpage-breaking

Currently my preamble looks like

\documentclass{article}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{enumitem}

\theoremstyle{definition}
\newtheorem*{theo}{Theorem}
\newtheorem*{defi}{Definition}
\newtheorem*{lem}{Lemma}
\newtheorem*{rem}{Remark}
\newtheorem*{col}{Corollary}

\title{Linear Algebra \\ Lecture Summary}
\date{}
\author{}

\begin{document}
\maketitle

\end{document}

I'd like it so when I write a theorem/lemma/remark/corollary it doesn't get split across pages.

I've searched for answers a few times, but I haven't got a lot of experience with TeX, and just copying and pasting what I see doesn't quite cut it.

Best Answer

The macro \blocktheorem{<theorem>} turns <theorem> into an unbreakable block by wrapping it inside a minipage:

enter image description here

\documentclass{article}
\usepackage{amsthm}
\usepackage{xparse,etoolbox}
\usepackage[nopar]{lipsum}% Just for this example
\usepackage[margin=1in,paper=a5paper]{geometry}% Just for this example

\theoremstyle{definition}
\newtheorem*{theo}{Theorem}
\newtheorem*{defi}{Definition}
\newtheorem*{lem}{Lemma}
\newtheorem*{rem}{Remark}
\newtheorem*{col}{Corollary}

\newcommand{\blocktheorem}[1]{%
  \csletcs{old#1}{#1}% Store \begin
  \csletcs{endold#1}{end#1}% Store \end
  \RenewDocumentEnvironment{#1}{o}
    {\par\addvspace{1.5ex}
     \noindent\begin{minipage}{\textwidth}
     \IfNoValueTF{##1}
       {\csuse{old#1}}
       {\csuse{old#1}[##1]}}
    {\csuse{endold#1}
     \end{minipage}
     \par\addvspace{1.5ex}}
}

\raggedbottom

\blocktheorem{theo}% Make theo into a block
\blocktheorem{defi}% Make defi into a block
\blocktheorem{lem}% Make lem into a block
\blocktheorem{rem}% Make rem into a block
\blocktheorem{col}% Make col into a block

\begin{document}

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

\lipsum[1]

\begin{defi}[abc]
\lipsum[1]
\end{defi}

\lipsum[1]

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

\lipsum[1]

\begin{rem}[abc]
\lipsum[1]
\end{rem}

\lipsum[1]

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

\end{document}

\raggedbottom helps with avoid underfull \vboxes due to the boxes being flushed to a successive page.