\item 后不需要的垂直空间

\item 后不需要的垂直空间

如果我运行以下代码

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}
\def\myproof#1{{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

然后我会得到

在此处输入图片描述

第二个上方的垂直间距很差证明

我可以通过在之后添加%或来解决这个问题\leavevmodeThis.

但是,有没有什么办法可以通过改变的定义来首先防止这种情况发生\myproof

答案1

你需要\par在 前面\color{blue}

您的示例中的情况是,来自行尾的空格后跟 ,{\color{blue}\begin{proof}...}\par发出的\begin{proof}(实际上是\trivlist,但这并不重要)无法将其删除。因此构建了仅包含一个空格的行。

从以下示例中可以看出,用 掩盖结束线可以%消除虚假线。

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}
\def\myproof#1{{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.%
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

在此处输入图片描述

如果我们将其修改为

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage{color}
\usepackage{amsmath}
\usepackage{amsthm}

\newcommand\myproof[1]{\par{\color{blue}\begin{proof}#1 \end{proof}}}

\begin{document}
\begin{enumerate}
  \item 1
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.%
  \myproof{sdf}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \myproof{sdf}
\end{enumerate}
\end{document}

您会发现%不再需要了。

在此处输入图片描述

我喜欢的方式是

\newenvironment{blueproof}{\par\color{blue}\proof}{\endproof}

使用

\begin{enumerate}
  \item 1
  \begin{blueproof}
  sdf
  \end{blueproof}
  \item Thisis Thisis This is This is This is This is This is This is This is This.
  \begin{blueproof}
  sdf
  \end{blueproof}
\end{enumerate}
\end{document}

相关内容