我已经创建了自定义阴影定理,但是当以 displaymath 或 itemize/enumerate 环境结束时,会出现额外的垂直空间。
以下是 MWE:
\documentclass{article}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{framed}
\newtheoremstyle{thm}
{0pt} % space above
{0pt} % space below
{\rmfamily} % body font
{} % indent amount
{\rmfamily} % theorem head font
{.} % punctuation after theorem head
{0.5em} % space after theorem head
{} % theorem head spec
\theoremstyle{thm}
\newtheorem{boilerexample}[section]{Example}
\newenvironment{example}
{\colorlet{shadecolor}{teal!15}\begin{shaded}\begin{boilerexample}}
{\end{boilerexample}\end{shaded}}
\begin{document}
\begin{example}
This is an example.
\end{example}
\begin{example}
This is an example that ends with displaymath.
\[ \sum_{k=1}^\infty \frac{1}{k} \]
\end{example}
\begin{example}
This is an example that ends with an itemize environment.
\begin{itemize}
\item This is an item.
\end{itemize}
\end{example}
\end{document}
第二和第三环境中的额外垂直空间是不可取的。有办法解决这个问题吗?
答案1
这可能会起作用:最后一个垂直跳跃被移除。
\documentclass{article}
\usepackage{amsthm}
\usepackage{xcolor}
\usepackage{framed}
\newtheoremstyle{thm}
{0pt} % space above
{0pt} % space below
{\rmfamily} % body font
{} % indent amount
{\rmfamily} % theorem head font
{.} % punctuation after theorem head
{0.5em} % space after theorem head
{} % theorem head spec
\theoremstyle{thm}
\newtheorem{boilerexample}[section]{Example}
\newenvironment{example}
{\colorlet{shadecolor}{teal!15}\begin{shaded}\begin{boilerexample}}
{%
\end{boilerexample}%
\par\removelastskip
\end{shaded}
}
\begin{document}
\begin{example}
This is an example.
\end{example}
\begin{example}
This is an example that ends with displaymath.
\[ \sum_{k=1}^\infty \frac{1}{k} \]
\end{example}
\begin{example}
This is an example that ends with an itemize environment.
\begin{itemize}
\item This is an item.
\end{itemize}
\end{example}
\end{document}