考虑以下 MWE:
\documentclass{amsart}
\usepackage{mdframed}
\newtheorem{definition}{Definition}[section]
\begin{document}
\begin{mdframed}
\begin{definition}
badsfhadsgufeiklufheiuwfhkusbadf
\end{definition}
\end{mdframed}
\end{document}
是否可以将框架设为默认值,即将其包含在序言中,以便每个定义、定理等都默认有一个框架?
答案1
tcolorbox
要么提供自己的高度可配置的框架theorem
环境,要么使用包装现有环境\tcolorboxenvironment{definition}{some options}
,其中definition
是在 OP 中定义的环境。
\documentclass{amsart}
\usepackage[most]{tcolorbox}
\newtheorem{definition}{Definition}[section]
\tcolorboxenvironment{definition}{enhanced jigsaw,colback={white!40!yellow}, colframe=red,boxrule=2pt, sharp corners}
\newtcbtheorem[auto counter, number within={section}]{Definition}{Definition}{enhanced jigsaw,colback={white!40!yellow}, colframe=blue,boxrule=2pt, sharp corners}{def:}
\begin{document}
\section{Foo}
\begin{definition}
badsfhadsgufeiklufheiuwfhkusbadf
\end{definition}
\begin{Definition}{My tcolorbox theorem}{exampleone}
badsfhadsgufeiklufheiuwfhkusbadf
\end{Definition}
\end{document}
用于定义定理的通用接口:
\documentclass{amsart}
\usepackage{xparse}
\usepackage[most]{tcolorbox}
\NewDocumentCommand{\newframedtheorem}{O{}momo}{%
\IfNoValueTF{#3}
{%
\IfNoValueTF{#5}
{\newtheorem{#2}{#4}}
{\newtheorem{#2}{#4}[#5]}%
}
{\newtheorem{#2}[#3]{#4}}
\tcolorboxenvironment{#2}{#1}%
}
\newframedtheorem{theorem}{Theorem}[section]
\theoremstyle{definition}
\newframedtheorem[
enhanced jigsaw,
colback={white!40!yellow},
colframe=red,
boxrule=2pt,
sharp corners,
]{definition}[theorem]{Definition}
\begin{document}
\section{Foo}
\begin{theorem}[Important]
Something neat to state.
\end{theorem}
\begin{definition}[Dull]
Something neat to define.
\end{definition}
\end{document}
环境\newframedtheorem
具有框架选项的初始可选参数(参见definition
),然后是的常用参数\newtheorem
。它遵循通常的样式设置。
答案2
您可以使用thmtools
包,它有一个mdframed
键来定义新定理。对于具有背景颜色的简单框架,我定义了一个framed
键,因此可以使用包framed
中的环境framed
。它可以跨页面拆分。
\documentclass{amsart}
\usepackage[x11names]{xcolor}
\usepackage{framed, etoolbox}
\colorlet{framecolor}{VioletRed4}
\colorlet{shadecolor}{LavenderBlush2!60}
\usepackage{thmtools} %
\makeatletter
\define@key{thmdef}{frame}[{}]{%
\thmt@trytwice{}{%
\RequirePackage{framed}%
\RequirePackage{thm-patch}%
\def\FrameCommand{\fcolorbox{framecolor}{shadecolor}}
\addtotheorempreheadhook[\thmt@envname]{%
\begin{framed}}%
\addtotheorempostfoothook[\thmt@envname]{\end{framed}}%
}%
}
\makeatother
\declaretheorem[numberwithin=section, frame]{definition}
\declaretheorem[frame, sharenumber=definition]{proposition}
\AtBeginEnvironment{proposition}{\colorlet{framecolor}{DarkSeaGreen4}
\colorlet{shadecolor}{Yellow1!15}}
\begin{document}
\setcounter{section}{3}
\begin{definition}
badsfhadsgufeiklufheiuwfhkusbadf
\end{definition}
\begin{proposition}
badsfhadsgufeiklufheiuwfhkusbadf
\end{proposition}
\end{document}