[Tex/LaTex] Is a \vspace placed on the end of a paragraph a bad LaTeX coding

horizontalparagraphsspacingvertical

After a comment of @DavidCarlisle in a question about \vspace usage I tried to find out if, when and why a \vspace command should be avoided to added as a last command of a paragraph in order to add or to remove space between paragraphs, like:

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

This is the text of the next paragraph.

@DavidCarlisle answered in a comment of mine that:

"the blank line should be before the vspace. Using vspace in horizontal
mode is well defined but weird, you almost always want to avoid that."

So, the proposed "correction" (as far as I can understand) is:

This is the text of a paragraph here.

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

But I tried many examples and didn't found one that would give an unexpected output (in order of vertical spacing, but general too). Also, in my first LaTeX steps I was using this style:

This is the text of a paragraph here.

\vspace{1cm}

This is the text of the next paragraph.

that now seems awful to me but could be consider as better LaTeX coding from my first example (the style that I am currently using).

So, my question is:

  1. Should I avoid the coding style of the first example for some reason?
  2. Is there any example that my style will fail in the expected spacing? (or this is just about code style)

MWE:

\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}

and output of MWE:

enter image description here

Best Answer

if you use \vspace at the end of a paragraph it probably gives the same visual result as using it in the following vertical list but via a wildly different and more involved code path. If you use vspace in vmode it just directly adds the glue node to the current vertical list. If you use it in h mode then the vertical glue is added to a vadjust node in the current horizontal list which will, after linebreaking, migrate to the current vertical list and be re-inserted into the vertical list after the line that contained the vadjust node.

You should almost always precede \vspace by a blank line or \par.

In practice the difference should not be an issue as there should almost never be explicit vertical space commands within the document. If there are, it is usually a sign that the global spacing set up by the class is not suitable for the current document and it is better to fix that at source rather than adjust spacing in each individual paragraph.

Related Question