3

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,
headfont=\normalfont\bfseries,
postheadspace=1em,
notefont=\bfseries,
notebraces={(}{)},
bodyfont=\itshape,
shaded={bgcolor=yellow!20}
]{thmstyle}

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

\begin{document}

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

\renewcommand{\listtheoremname}{List of Theorems}
\addcontentsline{toc}{section}{\listtheoremname}
\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?

2 Answers 2

2

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[
headfont=\normalfont\bfseries,
postheadspace=1em,
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:

enter image description here

4
  • 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?
    – SoftTimur
    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?
    – SoftTimur
    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
2

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}
\theoremheaderfont{\upshape\bfseries}
\theorembodyfont{\itshape}
\theoremseparator{.}
\colorlet{shadecolor}{yellow!20}
\def\theoremframecommand{\colorbox{shadecolor}}
\newshadedtheorem{theorem}{Theorem}


\def\theoremframecommand{\setlength\fboxrule{1pt}\colorlet{shadecolor}{LavenderBlush2!60!}\fcolorbox{framecolor}{shadecolor}}
\theoremheaderfont{\scshape}
\theorembodyfont{\upshape}
\newshadedtheorem{defi}{Definition}

\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
\colorlet{shadecolor}{LavenderBlush2}
\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}
\addcontentsline{toc}{section}{\listtheoremname}
\listtheorems{theorem,defi}

\end{document} 

enter image description here

2
  • 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?
    – SoftTimur
    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.
    – Bernard
    Jun 13, 2015 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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