1

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

  • 1
    Use \vspace inside a paragraph if you really want to space out two lines of that paragraph. If you want to space two paragraphs, use the code you find ugly, but which actually is the correct one. – egreg Mar 11 '19 at 23:07
  • You may also inadvertently use \vspace at the end of a line, then not leave a blank space, but think you've started a new paragraph. This is a special case of what @egreg mentions. – Werner Mar 11 '19 at 23:11
  • @egreg ... Thanks for the suggestion... Do you think that the first example and the last one (the ugly) will give a different output in some case? I just can't find such a case and was wondering if there is a difference that could create problems to me? Is it about bad styling or a different unexpected (from me that I am not too advanced LaTeX user) could come out by the first style? (If yes... then it is not just the style of course)... – koleygr Mar 11 '19 at 23:13
  • 1
    @koleygr If you don't find other reasons for avoiding \vspace next to the last word of a paragraph, then consider clarity of input. – egreg Mar 11 '19 at 23:22
  • 1
    @koleygr I suspect that (with standard definitions) the spacing is always the same, it's just that it feels wrong to use an obviously vertical command in h-mode. and certainly it makes Tex work harder, – David Carlisle Mar 11 '19 at 23:46
5

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.

  • Thank you very much @David ... I read your answer almost immediately and upvoted but had to check all the comments and to make my tests in order to leave the accepting after answering to anyone and having a clear opinion on all these. Thanks... (and goodnight) – koleygr Mar 11 '19 at 23:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.