如何增加定理的 \tcolorboxenvironment 上方和下方的空间?

如何增加定理的 \tcolorboxenvironment 上方和下方的空间?

以下源代码使用\tcolorboxenvironment{theorem}环境(来自tcolorbox包)来为环境的背景着色theorem,其中thmtools已用于定义定理样式。

proposition如何才能使该环境上方和下方的空间与环境(使用相同的)相同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\thmt@space\@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}

盒状定理上方和下方间距不足

为什么我要使用\tcolorboxenvironment而不是仅仅使用\newtcbtheorem因为我需要充分利用thmtools这里未指明的各种目的。

我尝试过

  • 在 中\tcolorboxenvironment{theorem},将最后两个键更改为top=12pt,bottom=12pt。但是,这只会改变框内文本上方和下方的空间量,而不会改变框与 ( kantsum) 框上方和下方文本之间的空间。
  • 而不是使用tcolorbox,而是在\declaretheoremstyle附加键中添加shaded=bgcolor=mythmback},但这似乎没有任何效果。

答案1

tcolorbox可以使用before skip和控制上方和下方的空间after skip,例如:

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

据我所知,tcolorbox环境可选参数中允许的所有选项都可以在的第二个参数中使用\tcolorboxenvironment

完整代码:

\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\thmt@space\@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}

在此处输入图片描述

相关内容