How to increase space above & below \tcolorboxenvironment for theorems?

by murray   Last Updated August 01, 2020 11:23 AM - source

The following source uses the \tcolorboxenvironment{theorem} environment (from the tcolorbox package) to shade the background of the theorem environment, where thmtools has been used to define the theorem style.

How can the space above and below that environment — so that it is the same as for the proposition environment (which uses the same theoremstyle)?

\documentclass{memoir}
\usepackage{newtxtext}
\usepackage[dvipsnames]{xcolor}
\usepackage[theorems]{tcolorbox}
\usepackage{amsthm}
\usepackage{thmtools}
\swapnumbers

\makeatletter
\declaretheoremstyle[
  headfont= \sffamily\bfseries\color{cyan!50!black},
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\bfseries,
  headformat=\NAME\NUMBER\let\[email protected]\@empty\NOTE,
  bodyfont=\mdseries\slshape,
  spaceabove=12pt,spacebelow=12pt,
  % trying color shading but does nothing ??
  %shaded={bgcolor=mythmback},
]{thmstyle}
\makeatother

\theoremstyle{thmstyle}
\declaretheorem[name=Theorem,numberwithin=chapter]{theorem}
\newtheorem{proposition}[theorem]{Proposition}

% For colored boxes
\definecolor{lightcyan}{rgb}{0.88, 1.0, 1.0}
\colorlet{mythmback}{lightcyan!40!white}

\tcolorboxenvironment{theorem}{%
colback=mythmback,coltitle=blue,colframe=mythmback,
left=0pt,right=0pt,
% next 2 keys just change spacing above, below text within_ the frame, not above, below environment
top=0pt,bottom=0pt,}

\usepackage{kantlipsum}

\begin{document}

\chapter{Chapter One}
\section{The section}
\kant[1]

\begin{theorem}
The square on the hypotenuse of a right triangle equals the sum of the squares of the hypotenuses on the other two sides.
\end{theorem}
\kant[2]

\begin{proposition}
A set is infinite if and only if it has a proper subset that can be put into one-to-one correspondence with the entire set.
\end{proposition}

\kant[3]

\end{document}

Insufficient spacing above and below boxed theorem

Why did I use \tcolorboxenvironment instead of just \newtcbtheorem? Because I need the full power of thmtools for various purposes not indicated here.

What I tried

  • In \tcolorboxenvironment{theorem}, to change the last two keys to top=12pt,bottom=12pt. However, this just changes the amount of space above and below the text within the box, not the space of the box from the (kantsum) text above and below the box.
  • Instead of using tcolorbox, adding within the \declaretheoremstyle the additional key shaded=bgcolor=mythmback}, but this seems to have no effect whatsoever.


Answers 1


The space above and below the tcolorbox can be controlled with before skip and after skip, for instance:

\tcolorboxenvironment{theorem}{
  colback=mythmback,coltitle=blue,colframe=mythmback,
  left=0pt,right=0pt,
  top=0pt,bottom=0pt,
  before skip=10pt, after skip=10pt,
}

As far as I know, all options allowed in the optional argument of the tcolorbox environment should be fine to use in the second argument of \tcolorboxenvironment.

Full code:

\documentclass{report}
\usepackage{tcolorbox}
\usepackage{amsthm}
\usepackage{thmtools}
\swapnumbers

\makeatletter
\declaretheoremstyle[
  headfont= \sffamily\bfseries\color{cyan!50!black},
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\sffamily\bfseries,
  headformat=\NAME\NUMBER\let\[email protected]\@empty\NOTE,
  bodyfont=\mdseries\slshape,
  spaceabove=12pt,spacebelow=12pt,
  % trying color shading but does nothing ??
  %shaded={bgcolor=mythmback},
]{thmstyle}
\makeatother

\theoremstyle{thmstyle}
\declaretheorem[name=Theorem,numberwithin=chapter]{theorem}
\newtheorem{proposition}[theorem]{Proposition}

% For colored boxes
\definecolor{lightcyan}{rgb}{0.88, 1.0, 1.0}
\colorlet{mythmback}{lightcyan!40!white}

\tcolorboxenvironment{theorem}{
  colback=mythmback,coltitle=blue,colframe=mythmback,
  left=0pt,right=0pt,
  top=0pt,bottom=0pt,
  before skip=10pt, after skip=10pt,
}

\usepackage{kantlipsum}

\begin{document}

\chapter{Chapter One}
\section{The section}
\kant[1]

\begin{theorem}
The square on the hypotenuse of a right triangle equals the sum of the squares of the hypotenuses on the other two sides.
\end{theorem}
\kant[2]

\begin{proposition}
A set is infinite if and only if it has a proper subset that can be put into one-to-one correspondence with the entire set.
\end{proposition}

\kant[3]

\end{document}

enter image description here

frougon
frougon
May 12, 2020 07:41 AM

Related Questions


Theorems spanning pages without losing width

Updated June 12, 2015 22:10 PM

thmtools notebraces bug?

Updated August 19, 2015 17:10 PM


Defining a new environment out of `restatable`

Updated March 24, 2018 13:23 PM