![如何增加定理的 \tcolorboxenvironment 上方和下方的空间?](https://linux22.com/image/413823/%E5%A6%82%E4%BD%95%E5%A2%9E%E5%8A%A0%E5%AE%9A%E7%90%86%E7%9A%84%20%5Ctcolorboxenvironment%20%E4%B8%8A%E6%96%B9%E5%92%8C%E4%B8%8B%E6%96%B9%E7%9A%84%E7%A9%BA%E9%97%B4%EF%BC%9F.png)
以下源代码使用\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}