使用 etoolbox 中 \AfterEndEnvironment 中的 \noindent 会导致两个环境之间的差距更大

使用 etoolbox 中 \AfterEndEnvironment 中的 \noindent 会导致两个环境之间的差距更大

使用\noindentin \AfterEndEnvironmentfrometoolbox会在两个环境之间产生比应有的更大的间隙。以下是完整描述该问题的代码。

\documentclass{scrartcl}
\usepackage{etoolbox}
\usepackage{amsthm}
\newtheorem{Th}{Theorem}
\AfterEndEnvironment{Th}{\noindent\ignorespaces}
\AfterEndEnvironment{proof}{\noindent\ignorespaces}
\begin{document}
\begin{Th}
This is just some theorem. This is just some theorem. This is just some theorem.
This is just some theorem. This is just some theorem. This is just some theorem.
This is just some theorem. This is just some theorem.
\end{Th}
\begin{proof}
This is just some proof. Note that the gap between the upper Theorem and this
proof is quite recognizable. It should not be this big. This is just some proof.
This is just some proof. This is just some proof. This is just some proof. 
\end{proof}
Now in contrast to the gap above, the gap bewteen an environment and plain text
seems to be normal. How can I reduce the gap between two environments without
hurting the correct gap between environments and plain text?
\end{document}

另外,这是 PDF 的图片: pdf 的图片

如果我删除这些\AfterEndEnvoronment东西,定理和证明之间的距离确实会变小。

有人能帮忙吗?非常感谢。

答案1

LaTeX 有一个内置机制来抑制环境后面段落的缩进。可以通过\@endpetrue在环境内部设置来使用此机制,但是amsthm使用代码始终\@endpefalse在定理环境的末尾设置(所使用的底层环境amsthm通常会使用该机制)。

因此,最简单的方法就是将其\@endpefalse从您的环境中移除。

之后,您得到的基本上是列表类环境的行为,如果您在后面放一个空行,\end{Th}您将得到一个缩进的段落。如果您省略空行,则以下段落不会缩进。

但请注意,从语义角度来看,证明或定理的末尾应该有一个新段落,因此应该有缩进。无论如何,以下内容可以满足您的要求:

\documentclass{scrartcl}
\usepackage{etoolbox}
\usepackage{amsthm}
\newtheorem{Th}{Theorem}
\makeatletter
\patchcmd{\endproof}{\@endpefalse}{}{}
\patchcmd{\endTh}{\@endpefalse}{}{}
\makeatother
\begin{document}
\begin{Th}
This is just some theorem. This is just some theorem. This is just some theorem.
This is just some theorem. This is just some theorem. This is just some theorem.
This is just some theorem. This is just some theorem.
\end{Th}
\begin{proof}
This is just some proof. Note that the gap between the upper Theorem and this
proof is quite recognizable. It should not be this big. This is just some proof.
This is just some proof. This is just some proof. This is just some proof. 
\end{proof}
Now in contrast to the gap above, the gap bewteen an environment and plain text
seems to be normal. How can I reduce the gap between two environments without
hurting the correct gap between environments and plain text?
\end{document}

在此处输入图片描述

相关内容