如何抑制证明环境头和逐项环境之间的垂直空间?

如何抑制证明环境头和逐项环境之间的垂直空间?

用户“egreg”最近帮助我抑制了定理头和enumitem环境(例如itemize;参见下面的链接)之间的垂直空间。我现在遇到了类似的问题:当proof环境以开始时itemize,垂直空间过多。如何proof重新定义环境,以便抑制(至少部分抑制)这个空间?

理想情况下,它应该是一个“干净”的解决方案,以便人们可以\begin{proof}按照要求输入\begin{itemize},而中间不需要输入复杂的命令。

通过将proof环境重新定义为定理,可以规避该问题,但如何才能将 qed 符号很好地放置?不确定这是否是一种好方法。

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{enumitem}

% theorems
\newif\ifstarttheorem
\newtheoremstyle{mythmstyle}%
{0.5em}%
{0.5em}%
{}% 
{}% 
{\sffamily\bfseries\global\starttheoremtrue}% 
{}% 
{\newline}% 
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% 
\theoremstyle{mythmstyle}% 

% proofs
\renewcommand*\proofname{Proof}
\makeatletter% q.e.d. adjustment (posted by ???)
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont\topsep2\p@\@plus2\p@\relax
  \trivlist
\item[\hskip\labelsep
  \sffamily\bfseries #1]\mbox{}\hfill\\*\ignorespaces
}{%
  \popQED\endtrivlist\@endpefalse
}
\makeatother

% suppress vertical spacing (for itemize) when newtheorems start with an environment
% see http://tex.stackexchange.com/questions/60001/nested-enumerate-enumitem-interferes-with-suppressing-vertical-space-after-the
\makeatletter
\preto\itemize{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse
    \fi
  \fi}
\preto\enditemize{\global\starttheoremfalse}
\makeatother

% document
\begin{document}
Let's prove something:
\begin{proof}
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a nicer vertical spacing:
\begin{proof}
  Just some text:
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a version with itemize:
\begin{proof}
  \begin{itemize}
    \item $x=y,\quad y=z\quad\Rightarrow\quad x=z.$
  \end{itemize}
\end{proof}
\end{document}

答案1

您可以尝试以下操作。此处环境证明获得一个新标志\starttheoremtrue,并且环境名称保存在命令中\mycurrenvir

\documentclass{scrartcl}

\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[american]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{etoolbox}
\usepackage{enumitem}

% theorems
\newif\ifstarttheorem
\newtheoremstyle{mythmstyle}%
{0.5em}%
{0.5em}%
{}% 
{}% 
{\sffamily\bfseries\global\starttheoremtrue}% 
{}% 
{\newline}% 
{\thmname{#1}\ \thmnumber{#2}\ \thmnote{(#3)}}% 
\theoremstyle{mythmstyle}% 

% proofs
\renewcommand*\proofname{Proof}
\makeatletter% q.e.d. adjustment (posted by ???)
\renewenvironment{proof}[1][\proofname]{\par
  \pushQED{\qed}%
  \normalfont\topsep2\p@\@plus2\p@\relax
  \trivlist
\item[\hskip\labelsep
  \sffamily\bfseries #1]\gdef\mycurrenvir{proof}\global\starttheoremtrue\mbox{}\hfill\\*\ignorespaces
}{%
 \gdef\mycurrenvir{\relax}
  \popQED\endtrivlist\@endpefalse
}
\makeatother

% suppress vertical spacing (for itemize) when newtheorems start with an environment
% see http://tex.stackexchange.com/questions/60001/nested-enumerate-enumitem-interferes-with-suppressing-vertical-space-after-the
\makeatletter
\preto\itemize{%
  \if@inlabel
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
  \fi%
 \def\tempa{proof}%
 \ifx\tempa\mycurrenvir
    \ifstarttheorem
      \mbox{}\par\nobreak\vskip\glueexpr-\parskip-\baselineskip+0.3em\relax\hrule\@height\z@
      \global\starttheoremfalse%
    \fi%
 \fi%
}
\preto\enditemize{\global\starttheoremfalse}
\makeatother

% document
\begin{document}
Let's prove something:
\begin{proof}
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a nicer vertical spacing:
\begin{proof}
  Just some text:
  \begin{align*}
    x=y,\quad y=z\quad\Rightarrow\quad x=z.
  \end{align*}
\end{proof}
Here a version with itemize:
\begin{proof}
  \begin{itemize}
    \item $x=y,\quad y=z\quad\Rightarrow\quad x=z.$
  \end{itemize}
\end{proof}
\end{document}

在此处输入图片描述

相关内容