TransWikia.com

How to increase space above & below tcolorboxenvironment for theorems?

TeX - LaTeX Asked on February 13, 2021

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= sffamilybfseriescolor{cyan!50!black},
  headpunct={sffamilybfseries.},
  postheadspace=0.5em,
  notefont=sffamilybfseries,
  headformat=NAMENUMBERletthmt@space@emptyNOTE,
  bodyfont=mdseriesslshape,
  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.

One Answer

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= sffamilybfseriescolor{cyan!50!black},
  headpunct={sffamilybfseries.},
  postheadspace=0.5em,
  notefont=sffamilybfseries,
  headformat=NAMENUMBERletthmt@space@emptyNOTE,
  bodyfont=mdseriesslshape,
  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

Correct answer by frougon on February 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP