我想做的事
我正在尝试构建一个定理及其证明如下:
我现在是如何做的
上面的图像是由以下代码生成的:
\documentclass[a4paper, 12pt]{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{amsthm}
\usepackage{xcolor}
\NewDocumentCommand{\newcoloredbox}{mm}{
\newmdenv[
roundcorner=4pt,
leftline=true,
rightline=true,
bottomline=true,
topline=true,
innertopmargin=7pt,
linecolor=black,
linewidth=1,
backgroundcolor=#2,
]{#1}
}
\newcoloredbox{theorembox}{green!20}
\newcoloredbox{proofbox}{white}
\newtheoremstyle{mytheoremstyle}
{0pt}
{\topsep}
{\itshape}
{0pt}
{\bfseries}
{}
{5pt plus 1pt minus 1pt}
{\thmnote{#3}. \hfill \thmname{#1} \thmnumber{#2}}
\theoremstyle{mytheoremstyle}
\newtheorem{theorem_}[equation]{Theorem}
\newenvironment{theorem}[1][]
{
\begin{theorembox}
\begin{theorem_}[#1] \leavevmode \\ \noindent
}
{
\end{theorem_}
\end{theorembox}
}
\newenvironment{fproof}[1][]
{
\vspace{-1.8em}
\begin{proofbox}
#1
}
{
\hfill \qedsymbol
\end{proofbox}
}
\begin{document}
\begin{theorem}[Some nice theorem]
Some extraordinary claim.
\end{theorem}
\begin{fproof}
Some unconvincing proof.
\begin{equation}
x + y = 1.
\end{equation}
\end{fproof}
\end{document}
问题
上述方法存在一些问题:
\vspace{-1.8em}
只需使用环境中的负空间,即可将证明盒与定理盒接触fproof
。我通过实验发现了这个值。有时证明盒和定理盒会重叠,这并不是故意的。右侧的“定理 1”与方程标记 (2) 不对齐。我希望它们从右侧对齐。
从下图也许可以更好地看到这些问题:
问题
我怎样才能以一种稳健的方式实现我想要做的事情?
答案1
这里有两个选项,tcolorbox
使用environment upper args
选项将定理包装在 tcolorbox 中。第一个选项将定理和证明集成在一个环境中,用 分隔\tcblower
。第二个选项对定理和证明使用两个单独的环境。请注意,我将句号移入,\thmnote
这样如果没有为定理提供标题,就不会打印句号。
\documentclass{article}
\usepackage{amsthm}
\usepackage{tcolorbox}
\tcbuselibrary{skins}
\newtheoremstyle{mytheoremstyle}
{0pt}
{\topsep}
{\itshape}
{0pt}
{\bfseries}
{}
{5pt plus 1pt minus 1pt}
{\thmnote{#3.}\hfill\thmname{#1} \thmnumber{#2}\newline}
\theoremstyle{mytheoremstyle}
\newtheorem{theorem}{Theorem}
\newtcolorbox{boxtheorem}[1][]{
environment upper args={theorem}{[#1]},
after lower=\qed,
bicolor,
colback=green!20,
colbacklower=white,
}
\newtcolorbox{boxtheoremnoproof}[1][]{
environment upper args={theorem}{[#1]},
colback=green!20,
after skip=0pt,
}
\newtcolorbox{boxproof}{
before skip=0pt,
colback=white,
after upper=\qed
}
\begin{document}
\begin{boxtheorem}[Some nice theorem]
Some extraordinary claim.
\tcblower
Some unconvincing proof.
\begin{equation}
x+y=1
\end{equation}
\end{boxtheorem}
\begin{boxtheoremnoproof}
Another extraordinary claim.
\end{boxtheoremnoproof}
\begin{boxproof}
Another unconvincing proof.
\begin{equation}
x+y=1
\end{equation}
\end{boxproof}
\end{document}
答案2
我找到了解决此问题的方法,如下所示:
问题 1:使用
skipabove
和skipbelow
参数mdframed
将定理skipbelow
和证明设置skipabove
为 0pt。这会将框放在彼此后面。要使线条重合,请替换\vspace{-1.8em}
为\vspace{-1pt}
以匹配线条的宽度。问题2:在定理定义
{5pt plus 1pt minus 1pt}
中用替换。{0pt}
修复后的代码如下:
\documentclass[a4paper, 12pt]{article}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{amsthm}
\usepackage{xcolor}
\NewDocumentCommand{\newcoloredbox}{mmO{1em}O{1em}}{
\newmdenv[
roundcorner=4pt,
leftline=true,
rightline=true,
bottomline=true,
topline=true,
innertopmargin=7pt,
linecolor=black,
linewidth=1,
backgroundcolor=#2,
skipabove=#3,
skipbelow=#4,
]{#1}
}
\newcoloredbox{theorembox}{green!20}[1em][0pt]
\newcoloredbox{proofbox}{white}[0pt][1em]
\newtheoremstyle{mytheoremstyle}
{0pt}
{\topsep}
{\itshape}
{0pt}
{\bfseries}
{}
{0pt}
{\thmnote{#3}. \hfill \thmname{#1} \thmnumber{#2}}
\theoremstyle{mytheoremstyle}
\newtheorem{theorem_}[equation]{Theorem}
\newenvironment{theorem}[1][]
{
\begin{theorembox}
\begin{theorem_}[#1] \leavevmode \\ \noindent
}
{
\end{theorem_}
\end{theorembox}
}
\newenvironment{fproof}[1][]
{
\vspace{-1pt}
\begin{proofbox}
#1
}
{
\hfill \qedsymbol
\end{proofbox}
}
\begin{document}
\begin{theorem}[Some nice theorem]
Some extraordinary claim.
\end{theorem}
\begin{fproof}
Some unconvincing proof.
\begin{equation}
x + y = 1.
\end{equation}
\end{fproof}
\end{document}