7

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.

3
  • Related/duplicate: Unbreakable block
    – Werner
    Mar 20, 2015 at 0:11
  • I appreciate the quick response. Maybe I'm missing something, but it's not quite what I was looking for. I was hoping to have it so I didn't have to manual enter it each time, maybe add it to the theorem "environment", if I'm using that phrase right. Thanks though!
    – Ash
    Mar 20, 2015 at 0:18
  • 1
    Yes, you're phrasing it correctly. You want your cake and eat it.
    – Werner
    Mar 20, 2015 at 0:19

1 Answer 1

4

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .