I am typesetting a document using the memoir
documentclass. Currently, my theorems have the following definition (using macros provided by the ntheorem
package):
% THEOREMS
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\itshape}%
\theoremsymbol{}%
\theoremseparator{\ }%
\theoremprework{\needspace{2\baselineskip}\noindent\theoremhang\vspace*{-1.3ex}}%
\theorempostwork{\nopagebreak\noindent\theoremhung}%
\setlength{\theorempreskipamount}{-1ex}
\setlength{\theorempostskipamount}{-1ex}
\newtheorem{theorem}{Theorem}[chapter]%
where the \theoremprework
and \theorempostwork
respectively use the following two macros to decorate the theorem:
\newcommand{\theoremhang}{% top theorem decoration
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,2){\line(1,0){206}}% Top line
\multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,-1){1}}% Top left hang
\put(203,\iA){\line(0,-1){1}}% Top right hang
}%
\end{picture}%
\endgroup%
}%
\newcommand{\theoremhung}{% bottom theorem decoration
\nobreak
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,0){\line(1,0){206}}% Bottom line
\multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,1){1}}% Bottom left hang
\put(203,\iA){\line(0,1){1}}% Bottom right hang
}%
\end{picture}%
\endgroup%
}%
Here is a common view of a theorem based on these definitions:
The problem I am experiencing occurs around page breaking, where either of the graphics (\theoremhang
or \theoremhung
) occur close to the end of the page. I sometimes have \theoremhang
being orphaned at the bottom of a page and not 'sticking' to the theorem
environment. Other times \theoremhung
ends up being orphaned on a following page if the theorem
environment ends right at the bottom of the page.
My attempts at trying to keep things together used \needspace
and some negative vertical alignment (via \vspace
s). Although the former may help, the latter feels like a bit of a hack and neither sticks to the theorem
environment like I'd hope it would. Any idea how I can fix the problem and perhaps even optimize this look?
For completeness, here is a minimal working example containing the above definitions (including a proof
environment, also via ntheorem
) as well as a sample theorem/proof:
\documentclass{memoir}
\usepackage{amsmath}
\usepackage[amsmath]{ntheorem}%
\usepackage{lipsum,multido,graphicx,xcolor}
% THEOREMS
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\itshape}%
\theoremsymbol{}%
\theoremseparator{\ }%
\theoremprework{\needspace{2\baselineskip}\noindent\theoremhang\vspace*{-1.3ex}}%
\theorempostwork{\nopagebreak\noindent\theoremhung}%
\setlength{\theorempreskipamount}{-1ex}
\setlength{\theorempostskipamount}{-1ex}
\newtheorem{theorem}{Theorem}[chapter]%
% PROOF
\theoremheaderfont{\sffamily\bfseries\upshape}%
\theorembodyfont{\upshape}%
\theoremstyle{nonumberplain}%
\theoremseparator{\ }%
\theoremsymbol{}%
\setlength{\theorempreskipamount}{1ex}%
\newtheorem{proof}{Proof}%
\newcommand{\theoremhang}{% top theorem decoration
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,2){\line(1,0){206}}% Top line
\multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,-1){1}}% Top left hang
\put(203,\iA){\line(0,-1){1}}% Top right hang
}%
\end{picture}%
\endgroup%
}%
\newcommand{\theoremhung}{% bottom theorem decoration
\nobreak
\begingroup%
\setlength{\unitlength}{.005\linewidth}% \linewidth/200
\begin{picture}(0,0)(1.5,0)%
\linethickness{0.45pt} \color{black!50}%
\put(-3,0){\line(1,0){206}}% Bottom line
\multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
\color{black!\iB}%
\put(-3,\iA){\line(0,1){1}}% Bottom left hang
\put(203,\iA){\line(0,1){1}}% Bottom right hang
}%
\end{picture}%
\endgroup%
}%
\begin{document}
\chapter{First chapter}
\lipsum[1]
\begin{theorem}%
If~$G$ is a connected graph of order $n\geq 3$ and size~$m$, then
\[
g(G)\geq \frac{m}{6}-\frac{n}{2}+1.%
\]
\begin{proof}%
Suppose a connected graph~$G$ of order $n\geq 3$ and size~$m$ is embedded in a surface of genus~$g(G)$, thus producing~$f$ faces. Then it follows by Theorem~XX that every face is a 2-cell and hence by Theorem~YY that $n-m+f=2-2\,g(G)$. An identical argument as in the proof of Theorem~ZZ shows that $3f\leq 2m$ and so
\[
2-2\,g(G)=n-m+f\leq n-m+\frac{2m}{3},%
\]
from which the desired inequality follows.%
\end{proof}%
\end{theorem}%
\lipsum[2]
\end{document}