# Why does vspace add vertical space after the first line of a paragraph?

I have defined a custom text font command using :

\DeclareTextFontCommand{\desc}{
\fontsize{11pt}{11pt}
\fontseries{light}\selectfont
\vspace{10px}
}


And I have used it like that :

\desc{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed at tempor ex. Praesent a luctus enim. Nam mauris odio, ornare at egestas ut, mollis aliquet est. Nunc a rutrum tortor. Suspendisse et odio rutrum, porta ipsum non, fermentum turpis.}


I expected to have a 10 px space after the paragraph, but the space is added after the first line :

Also, why are the second and third lines are not aligned with the first line since I removed the indent of the paragraph? Those are shifted left in the margin of the page.

• Welcome to TeX.SE! Please show how you are using the macro. But I guess you are calling your macro in a paragraph (aka "horizontal mode") where the LaTeX macro \vspace expands to the TeX primitive \vadjust, which does what you see. See e.g. tex.stackexchange.com/a/30065/82917. Oh, and the indentation is likely the product of spurious spaces in your definition. But again, please post a minimal working example (MWE) showing the issue. Jun 7 at 17:14
• The identation problem was because of spaces, like you said. Adding empty comments after each line fixed it.
– Olon
Jun 7 at 18:15
• 11pt on 11pt is very tight (often unachievable) spacing, do you intend it to be that tightly spaced? Jun 7 at 18:37

\vspace adds the space at the point where it's called. So, for example if you write

Foo

\vspace{1in}
Foo


The space goes betwen paragraphs, while

Foo
\vspace{1in}
Foo


puts it after the line on which the first Foo appears. So surely, we should see, if we have

Foo

\desc{Foo}


that the space comes between the paragraphs, right? Except that you're using \DeclareTextFontCommand which does a little bit more. In particular, it does:

\def \DeclareTextFontCommand #1#2{%
\DeclareRobustCommand#1[1]{%
\ifmmode
\nfss@text{#2##1}%
\else
\hmode@bgroup % ❶
\text@command{##1}%
#2\check@icl ##1\check@icr
\expandafter
\egroup \fi
}


❶ is the critical line here. \hmode@bgroup leaves vertical mode (so it begins the paragraph) and then begins a group. So your \vspace is being output after the paragraph begins and comes after the first line.

Most likely, what you want is not to use \DeclareTextFontCommand at all. Assuming that you want to use this as a marker at the beginning of paragraphs, you could instead do:

\NewDocumentCommand{ m }{%
\par
\vspace{10px}
{%
\fontsize{11pt}{11pt}%
\fontseries{light}\selectfont
#1
}%
}


(Side note, I'd not seen px as a unit in TeX before. It's apparently equivalent to bp or the PostScript point of 1/72 in. It's not mentioned in The TeXbook as far as I know. Apparently an eTeX enhancement as it's an illegal unit if I use tex but is available with pdftex and any of the LaTeX engines which all require eTeX.)

• px came from pdftex (rather than pure etex) but etex these days is pdftex in dvi mode so it comes to the same thing:-) Jun 7 at 18:36

Environments are easier to use and and fixed my problem. The second {} contains the styles to apply before the text and the third {} contains the styles to apply after the text.

\newenvironment{desc}{%
\fontsize{11pt}{11pt}%
\fontseries{light}\selectfont%
\begin{spacing}{1.1}%
}{\end{spacing}\vspace{10px}}


Adding % after each line fixed my second problem. Without these, whitespace would shift the text right.