创建间距命令,消除后面的多余空格

创建间距命令,消除后面的多余空格

命令之后\section,无论后面是什么,空间量都是相同的。itemize环境不会添加额外的空间。

如何在自定义环境后实现相同的行为?

在此处输入图片描述

\documentclass{article}

\newlength{\postinfoskip}
\setlength{\postinfoskip}{2ex}

\newenvironment{info}
  {\itshape}
  {\vspace{\postinfoskip}}

\begin{document}
\section{The spacing after this section \dots}
This is a line of text that begins with a normal amount of space after the section heading.

\section{\dots{} is the same as the spacing after this one}
\begin{itemize}
\item First line of text
\item Second line of text
\end{itemize}

\section{But when I use a custom environment \dots}
\begin{info}
See how much space there is after this environment before normal text.
\end{info}

This is a line of text that begins with a normal amount of space after the environment.

\section{\dots{} I can't get consistent spacing after}
\begin{info}
Compare to the amount of space before itemize.
\end{info}

\begin{itemize}
\item First line of text starts after a gap
\item Second line of text
\end{itemize}
\end{document}

答案1

在这种情况下,我建议使用\addvspace而不是\vspace

\newlength{\postinfoskip}
\setlength{\postinfoskip}{2ex}
\newenvironment{info}
  {\itshape}
  {\par\addvspace{\postinfoskip}}

在此处输入图片描述

相关内容