我使用declaretheoremstyle
来声明一个定理环境。我喜欢 的格式shaded
,它给出了特殊的背景颜色,而不会缩短文本的宽度。但有一个问题是定理块不会跨越 2 页。因此,如果一个块太长,它会与页面的底部边距相交:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mdframed}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
postheadspace=1em,
notefont=\bfseries,
notebraces={(}{)},
bodyfont=\itshape,
shaded={bgcolor=yellow!20}
]{thmstyle}
\declaretheorem[style=thmstyle,name=Theorem]{theorem}
\begin{document}
\begin{theorem}[name]
...
\end{theorem}
\renewcommand{\listtheoremname}{List of Theorems}
\addcontentsline{toc}{section}{\listtheoremname}
\listoftheorems[ignoreall,show=theorem]
\end{document}
我尝试遵循这个主张通过使用preheadhook
和postfoothook
。它确实解决了跨越的问题,但它缩短了文本的宽度,正如我所展示的这里。
我想我会采用真实的宽度(如shaded
给出的),有人知道如何让它跨越 2 页吗?
答案1
使用mdframed
键与mdframed
包并将边距设置为适当的值(我在下面的代码中使用的设置重现了原始设置):
\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage{xcolor}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mdframed}
\usepackage{lipsum}
\declaretheoremstyle[
headfont=\normalfont\bfseries,
postheadspace=1em,
notefont=\bfseries,
notebraces={(}{)},
bodyfont=\itshape,
mdframed={
hidealllines=true,
skipabove=10pt,
backgroundcolor=yellow!20,
innerrightmargin=2pt,
innerleftmargin=2pt,
innertopmargin=0pt,
innerbottommargin=0pt,
leftmargin=-2pt,
rightmargin=-2pt,
}
]{thmstyle}
\declaretheorem[style=thmstyle,name=Theorem]{theorem}
\renewcommand{\listtheoremname}{List of Theorems}
\begin{document}
\lipsum[4]
\begin{theorem}[Some name]
\lipsum[4]
\end{theorem}
\lipsum[4]
\end{document}
输出:
答案2
framed
这是一个带有 选项的简单解决方案ntheorem
,其中有用于选择性排版定理列表的工具:
\documentclass{article}
\usepackage[english]{babel}
\usepackage[margin=2cm]{geometry}% just for the example
\usepackage[x11names]{xcolor}
\usepackage{lipsum}
\usepackage{amsmath}
\usepackage[thmmarks, thref, amsmath, framed]{ntheorem}
\usepackage{thmtools}
\usepackage{framed}
\colorlet{framecolor}{VioletRed4}
\theoremframepreskip{6pt}
\theoremframepostskip{6pt}
\theoreminframepreskip{4pt}
\theoreminframepostskip{4pt}
\theoremheaderfont{\upshape\bfseries}
\theorembodyfont{\itshape}
\theoremseparator{.}
\colorlet{shadecolor}{yellow!20}
\def\theoremframecommand{\colorbox{shadecolor}}
\newshadedtheorem{theorem}{Theorem}
\def\theoremframecommand{\setlength\fboxrule{1pt}\colorlet{shadecolor}{LavenderBlush2!60!}\fcolorbox{framecolor}{shadecolor}}
\theoremheaderfont{\scshape}
\theorembodyfont{\upshape}
\newshadedtheorem{defi}{Definition}
\theoremlisttype{allname}
\begin{document}
\vspace*{18cm}
Blahblahblah
\begin{theorem}[Named theorem]
Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text. Some text.
\lipsum[1]
\end{theorem}
Blah blah blah
\colorlet{shadecolor}{LavenderBlush2}
\begin{defi}
$ \boldsymbol \pi $ is the ratio of the perimeter of a circle to its diameter.
\end{defi}
%
%\renewcommand{\listtheoremname}{List of Theorems}
%\listoftheorems[ignoreall,show=theorem]
\section*{\listtheoremname}
\addcontentsline{toc}{section}{\listtheoremname}
\listtheorems{theorem,defi}
\end{document}