我正在尝试定义自己的证明环境,将证明分为几个步骤。我使用tcolorbox
包装proof
环境,并用 分隔各个步骤\tcbline*
。但是,在此之前,我还重新定义了proof
环境以摆脱“证明:”前缀。
\documentclass{article}
\usepackage{amsthm}
\usepackage[many]{tcolorbox}
% Renew proof environment to avoid "Proof." at the start.
\renewenvironment{proof}{\unskip\ignorespaces}{\hfill \qedsymbol}
% Creates a heading for a step of a proof.
\NewDocumentCommand{\proofpart}{m}{\tcbline*\noindent\textbf{#1}\vspace{0.25em}\newline}
% Wrap the proof environment in a tcolorbox.
\tcolorboxenvironment{proof}{}
\begin{document}
\begin{proof}
\proofpart{First (should not have line above)}
abc
\proofpart{Second (should have line above)}
abc
\proofpart{Third (should have line above)}
abc
\end{proof}
\end{document}
看起来像这样:
\tcbline*
如果前面没有文本,我希望不显示第一个。有办法实现吗?
答案1
如果上部第一段还未开始,则尝试跳过\tcbline*
。\proofpart
\documentclass{article}
\usepackage{amsthm}
\usepackage[many]{tcolorbox}
\newif\ifmytcbupperstarted
\tcbsetforeverylayer{
code={\mytcbupperstartedfalse},
before upper pre={\AddToHookNext{para/begin}{\mytcbupperstartedtrue}}
}
% Renew proof environment to avoid "Proof." at the start.
\renewenvironment{proof}{\unskip\ignorespaces}{\hfill \qedsymbol}
% Creates a heading for a step of a proof.
\NewDocumentCommand{\proofpart}{m}{%
\ifmytcbupperstarted\tcbline*\fi
\noindent\textbf{#1}\vspace{0.25em}\newline}
% Wrap the proof environment in a tcolorbox.
\tcolorboxenvironment{proof}{}
\begin{document}
\begin{proof}
\proofpart{First (should not have line above)}
abc
\proofpart{Second (should have line above)}
abc
\proofpart{Third (should have line above)}
abc
\end{proof}
\begin{tcolorbox}
\ifmytcbupperstarted\tcbline\fi
layer 1
\tcbline
layer 1
\begin{tcolorbox}
\ifmytcbupperstarted\tcbline\fi
layer 2
\tcbline
layer 2
\end{tcolorbox}
\end{tcolorbox}
\end{document}
原始版本
\tcbset{before upper pre={\AddToHookNext{para/begin}{\mytcbupperstartedtrue}}}
仅适用于最外层的tcolorbox
es。现在修订的版本也适用于嵌套的tcolorbox
es。