8

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?

1
  • 1
    You should try the theorem environment definitions provided by package mdframed
    – egreg
    Nov 10, 2011 at 20:48

1 Answer 1

13

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}
7
  • Oh dear. I was hoping to stick with thmtools, but it looks like I'll stick with mdframed from now. I will mark this as answered.
    – TSGM
    Nov 10, 2011 at 21:43
  • I noticed that you added an innertopmargin=0pt option to the theorem declaration, and yet there is still substantial spacing between the top of the shaded region and the top of the first line. What is the option which controls that spacing? It's strange, because I thought that it -was- innertopmargin
    – TSGM
    Nov 10, 2011 at 22:21
  • @TSGM: yes, innertopmargin controls that spacing; according to the documentation, its default values is 0.4\baselineskip, but apparently it really is bigger, setting it to 0pt has not the expected effect. I'll give a look at the code of the package to see what exactly is going on, but I don't promise anything (I can't spend too much time reading the code). Anyway, you could use innertopmargin =-.4\baselineskip (or any other suitable negative length) which apparently gives equal top and bottom spacing. Nov 10, 2011 at 23:17
  • 4
    @TGSM: thmtools' shade and box settings all pass through to thmbox (if I recall) anyway. Nothing stops you from adding \begin{mdframed} (or whatever its syntax is) to the beforehead/afterfoot hooks. Nov 11, 2011 at 5:36
  • @UlrichSchwarz: good point. Nov 11, 2011 at 13:04

You must log in to answer this question.

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