27

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.

1

1 Answer 1

21

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}
14
  • 1
    @Yiannis, I already gave @TH the link where you explained almost the same answer. Commented Dec 24, 2010 at 6:01
  • 1
    \offinterlineskip doesn't seem to be needed. And \prevdepth wasn't contributing anything in my example since it was 0pt. \topskip is really the culprit. As TeX by Topic points out, if you want to really start at the top of the page, you should use \hbox{}\kern-\topskip.
    – TH.
    Commented Dec 24, 2010 at 6:02
  • @TH I think it does (at least for my example), if you comment it out it will still have an effect. See TeXbook exercise 12.10. Why do you say in your example \topskip was zero?
    – yannisl
    Commented Dec 24, 2010 at 6:08
  • @xport yes thanks, I saw it but just wanted to clear all these in my mind as well and I thought you went for lunch, while I am having breakfast:)
    – yannisl
    Commented Dec 24, 2010 at 6:10
  • 1
    @TH Doesn't it shows zero because there was no last box yet?
    – yannisl
    Commented Dec 24, 2010 at 6:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .