Shaded Theorems – Spanning Pages with Thmtools

amsthmpage-breakingtheoremsthmtools

When the thmtools package is used to create theorem environments with a shaded background, it does not allow separate theorems to span more than one page. This is a rather severe problem if the document contains many long theorems, one after the other. Here is a minimal example.

\documentclass{minimal}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage[english]{babel}
\usepackage{blindtext}

\declaretheoremstyle[
    shaded={bgcolor=\color{rgb}{0.9,0.9,0.9}}  % comment this line in/out
]{theorem}
\declaretheorem[style=theorem]{theorem}

\begin{document}

\begin{theorem}
\blindtext[5]
\end{theorem}

\begin{theorem}
\blindtext[5]
\end{theorem}

\end{document}

Here is what it looks like including and not including shading:
BadGood

How does one include shading, but allow the theorems to span between pages?

Best Answer

You can use \newmdtheoremenv from the mdframed package; a little example (change the lengths and other settings according to your needs):

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

\definecolor{mybg}{rgb}{0.9,0.9,0.9}

\newmdtheoremenv [backgroundcolor=mybg, %
innertopmargin =0pt , %
splittopskip = \topskip, % 
skipbelow= 6pt, %
skipabove=6pt, %
topline=false,bottomline=false,leftline=false,rightline=false,]{theorem}{Theorem}

\begin{document}

\begin{theorem}
\blindtext[5]
\end{theorem}

\begin{theorem}
\blindtext[5]
\end{theorem}

\end{document}

enter image description here

As Ulrich Schwarz comments, you can use the preheadhook, postfoothook hooks form thmtools to add the mdframed environment with the desired specifications:

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

\definecolor{mybg}{rgb}{0.9,0.9,0.9}

\declaretheoremstyle[
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont\itshape,
postheadspace=0.5em,
preheadhook={\begin{mdframed}[backgroundcolor=mybg, %
  innertopmargin =0pt , splittopskip = \topskip, % 
  skipbelow= 6pt, skipabove=6pt, %
  topline=false,bottomline=false,leftline=false,rightline=false]},
postfoothook=\end{mdframed}
]{mystyle}
\declaretheorem[style=mystyle]{theorem}

\begin{document}

\begin{theorem}
\blindtext[5]
\end{theorem}

\begin{theorem}
\blindtext[5]
\end{theorem}

\end{document}
Related Question