# Theorems spanning pages without losing width

I use declaretheoremstyle to declare a theorem environment. I like the format of shaded, it gives a special background color without shorten the width of a text. But one problem is that a theorem block does not span in 2 pages. So if a block is too long, it intersects with the bottom margin of the page:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mdframed}

\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
notefont=\bfseries,
notebraces={(}{)},
bodyfont=\itshape,
]{thmstyle}

\declaretheorem[style=thmstyle,name=Theorem]{theorem}

\begin{document}

\begin{theorem}[name]
...
\end{theorem}

\renewcommand{\listtheoremname}{List of Theorems}
\listoftheorems[ignoreall,show=theorem]

\end{document}


I tried to follow this proposition by using preheadhook and postfoothook. It does solve the problem of spanning, but it shortens the width of a text, as I showed here.

I think i will go with the authentic width (as shaded gives), does anyone know how to make it span in 2 pages?

Use the mdframed key to interact with the mdframed package and set the margins to the appropriate values (the settings I used in the code below reproduce the original settings):

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mdframed}
\usepackage{lipsum}

\declaretheoremstyle[
notefont=\bfseries,
notebraces={(}{)},
bodyfont=\itshape,
mdframed={
hidealllines=true,
skipabove=10pt,
backgroundcolor=yellow!20,
innerrightmargin=2pt,
innerleftmargin=2pt,
innertopmargin=0pt,
innerbottommargin=0pt,
leftmargin=-2pt,
rightmargin=-2pt,
}
]{thmstyle}

\declaretheorem[style=thmstyle,name=Theorem]{theorem}
\renewcommand{\listtheoremname}{List of Theorems}

\begin{document}

\lipsum[4]
\begin{theorem}[Some name]
\lipsum[4]
\end{theorem}
\lipsum[4]

\end{document}


The output:

• That works, thank you... Actually, the reason why I use declaretheoremstyle is to put a background color. So I would like the other things to be exactly the same as the default theorem environment. So do you think spacebelow, spaceabove and postheadspace are all well set (i.e., why are they 6pt or 1em)? And what about skipabove and skipbelow of mdframed? Jun 12, 2015 at 21:35
• @SoftTimur You're welcome. postheadspace has no problem. The new set of settings (at the bottom of my answer) will give you the desired result. Jun 12, 2015 at 21:45
• I tried your new setting, I think it shorten a little bit the width, no? Whereas, shaded does not shorten the width, its background shading exceeds a little bit the width... Also, should skipabove, skipbelow of mdframed be set? Should spacebelow and spaceabove be 6pt? Jun 12, 2015 at 21:52
• @SoftTimur No. The settings provided give a width equal to \textwidth for the text and the frame will protrude 2pt on both sides. I've updated my answer providing settings that (according to my tests) reproduce the settings of the shaded style you originally had. Jun 13, 2015 at 16:42

Here is a simple solution with the framed option of ntheorem, which has tools for selectively typeset theorem lists:

\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage[x11names]{xcolor}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage[thmmarks, thref, amsmath, framed]{ntheorem}
\usepackage{thmtools}

\usepackage{framed}
\colorlet{framecolor}{VioletRed4}
\theoremframepreskip{6pt}
\theoremframepostskip{6pt}
\theoreminframepreskip{4pt}
\theoreminframepostskip{4pt}
\theorembodyfont{\itshape}
\theoremseparator{.}

\theorembodyfont{\upshape}

\theoremlisttype{allname}
\begin{document}
\vspace*{18cm}

Blahblahblah
\begin{theorem}[Named theorem]
Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.

\lipsum[1]
\end{theorem}
Blah blah blah
\begin{defi}
$\boldsymbol \pi$ is the ratio of the perimeter of a circle to its diameter.
\end{defi}
%
%\renewcommand{\listtheoremname}{List of Theorems}
%\listoftheorems[ignoreall,show=theorem]
\section*{\listtheoremname}

• Thanks for your answer... As I commented, my ultimate goal is to put a background color. So I would like the other things to be exactly the same as the default theorem environment. So do you think theoremframepreskip, theoremframepostskip, theoreminframepreskip, theoreminframepostskip, etc. should be 6pt or 4pt? Jun 13, 2015 at 14:57
• I'm unsure of what what thmtools does exactly with ntheorem. I know they cooperate. I think it's up to you to choose the values you want, after testing with a viewer that lets make some measurements in the resulting .pdf (SumatraPDF let you do that). I can say the value of 6pt, in my code (theoremframepre and postskip), is added to the normal lineskip between the line above an the top of the shaded region (and similarly at the bottom). As to the \theoreminframepre and postskip, they're the vertical padding above (resp. below) the first (resp. last) line of the shaded environment. Jun 13, 2015 at 15:13