Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
I am not sure whether it is related to \topskip as explained here tex.stackexchange.com/questions/7286/… –  xport Dec 24 '10 at 5:01
add comment

1 Answer

up vote 13 down vote accepted

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}
share|improve this answer
1  
@Yiannis, I already gave @TH the link where you explained almost the same answer. –  xport Dec 24 '10 at 6:01
    
\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. Dec 24 '10 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? –  Yiannis Lazarides Dec 24 '10 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:) –  Yiannis Lazarides Dec 24 '10 at 6:10
1  
@TH Doesn't it shows zero because there was no last box yet? –  Yiannis Lazarides Dec 24 '10 at 6:37
show 9 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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