在段落末尾放置 \vspace 是一种错误的 LaTeX 编码吗?

在段落末尾放置 \vspace 是一种错误的 LaTeX 编码吗?

在发表评论后@DavidCarlisle在一个问题关于\vspace用法,我试图找出是否、何时以及为什么\vspace应该避免将命令添加为段落的最后一个命令,以便添加或删除段落之间的空格,例如:

This is the text of a paragraph here.\vspace{1cm}

This is the text of the next paragraph.

@DavidCarlisle 在我的评论中回答道:

“空白行应该位于垂直空间之前。在水平模式下使用垂直空间定义明确但又很奇怪,你几乎总是想避免这种情况。”

因此,建议的“更正”(据我所知)是:

This is the text of a paragraph here.

\vspace{1cm}This is the text of the next paragraph.

但是我尝试了很多例子,没有找到一个能给出意想不到的输出的例子(按垂直间距的顺序,但也很通用)。此外,在我的第一个 LaTeX 步骤中,我使用了这种风格:

This is the text of a paragraph here.

\vspace{1cm}

This is the text of the next paragraph.

现在对我来说这似乎很糟糕,但从我的第一个例子(我目前正在使用的风格)来看,可以被认为是更好的 LaTeX 编码。

所以,我的问题是:

  1. 由于某种原因,我是否应该避免使用第一个例子的编码风格?
  2. 有没有例子表明我的风格会在预期的间距内失败?(或者这只是关于代码风格)

梅威瑟:

\documentclass{article}
\usepackage{parskip}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\setlength{\parskip}{1cm plus 0cm minus 0cm}
\setlength{\parindent}{0pt}

\newcommand{\expectedVSkip}[2][2.2cm]{\begin{tikzpicture}[overlay,remember picture,baseline=0pt]\node[use as bounding box,inner sep=0,outer sep=0] at (0,0) (A){\vphantom{\texttt{p}}};\draw[->,blue] (A.south)--node[midway,right]{$#2$}($(A.south)+(0,-{#2})$);\draw[->,thin,blue] ($(A.south)+(-{#1},0)$)--($(A.south)+(0,0)$);\draw[->,thin,blue] ($(A.south)+(-{#1},-{#2})$)--($(A.south)+(0,-{#2})$);\end{tikzpicture}}

\begin{document}

This is the first paragraph that will have a space of the \verb|\parskip|$=1\;cm$ length from the following command since no \verb|\vspace|\expectedVSkip{1cm} command is added here.

This is the second paragraph that will have a space of $0.5\;cm$ from the folowing paragraph since a \verb|\vspace{-0.5cm}|\expectedVSkip{0.5cm} command is added just in its end.\vspace{-0.5cm}

This\vspace{2cm} is the third paragraph with a \verb|\vspace{2cm}|\expectedVSkip{2cm} command before the end of its first line. The paragpaph have enough text following, in order to let us discover if the \verb|\vspace| will act from the point of the first linebreak or from the end of this paragraph (Since the command is placed in its first line, the command is supposed to act just at the place that \LaTeX{} will deside to break the line and the paragraph will be an ugly broken paragraph with a strange added vertical space of exactly $2\;cm$). After this paragraph the following paragraph will be in distance of 2cm since an additional (just one) $cm$ have been added through a \verb|\vspace{1cm}|\expectedVSkip{2cm} to the \verb|\parskip|.\vspace{1cm}

This is just the fourth paragraph.


\end{document}

以及 MWE 的输出:

在此处输入图片描述

答案1

如果您\vspace在段落末尾使用,它可能会给出与在以下垂直列表中使用它相同的视觉效果,但通过完全不同且更复杂的代码路径。如果您在 vmode 中使用 vspace,它只会直接将粘合节点添加到当前垂直列表中。如果您在 h 模式下使用它,则垂直粘合将添加到当前水平列表中的 vadjust 节点,该节点将在换行后迁移到当前垂直列表并重新插入到包含 vadjust 节点的行后的垂直列表中。

您几乎总是应该\vspace在前面加上一个空行或\par

实际上,这种差异不应该成为问题,因为文档中几乎从来不会有明确的垂直间距命令。如果有,这通常表明该类设置的全局间距不适合当前文档,最好从源头上修复这个问题,而不是在每个段落中调整间距。

相关内容