Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
1  
You should try the theorem environment definitions provided by package mdframed –  egreg Nov 10 '11 at 20:48
add comment

1 Answer

up vote 10 down vote accepted

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}
share|improve this answer
    
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 '11 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 '11 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. –  Gonzalo Medina Nov 10 '11 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. –  Ulrich Schwarz Nov 11 '11 at 5:36
    
@UlrichSchwarz: good point. –  Gonzalo Medina Nov 11 '11 at 13:04
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.