[Tex/LaTex] Why does \vspace*{0pt} add vertical space

macrosspacingvertical alignment

I'm trying to format the title of the table of contents using the tocloft package. It inserts code that looks like the following.

\par
\vspace*{\cftbeforetoctitleskip}%
% code to typeset \contentsname

The \vspace* is adding unwanted space. Here's a minimal example demonstrating the problem.

\documentclass{article}
\usepackage{showframe}
\begin{document}
\vspace*{0pt}%
ASDF
\end{document}

Compare that to \vspace{0pt} (or simply omitting the \vspace line altogether).

The difference between \vspace and \vspace* is clear. With the star, it expands to

\dimen@\prevdepth
\hrule \@height\z@
\nobreak
\vskip#1%
\vskip\z@skip
\prevdepth\dimen@

and without the star, it expands to just the two \vskips.

Why is there the extra space? (And bonus question: Doesn't this make \vspace* sort of worthless since the star only has a use when TeX is discarding items?)

Edit:
I was able to fix my real problem (with the table of contents) by using \patchcmd from etoolbox.

Best Answer

To ensure that white space is produced even at points in the document where page breaking takes place or at the top or bottom of a page one should replace \vspace by \vspace*.

At the beginning of a page \topskip is inserted, normally \topskip=10pt. Setting topskip=0pt and \offinterlineskip will produce identical results both for vspace and vscpace*.

\documentclass{article}
\usepackage{showframe}
\begin{document}
\topskip=0pt  \offinterlineskip 
\vspace*{0pt}%
ASDF

\end{document}

\offinterlineskip is macro to prevent interline glue globally. Try running both examples to see the difference.

\documentclass{article}
\usepackage{showframe}
\begin{document}
\topskip=0pt  %\offinterlineskip 
\vspace*{0pt}%
ASDF
\end{document}