141

I'd like to, first thing before writing anything on a page, add some vertical space.

Minimal (non)working example:

\documentclass{article}
\begin{document}

\vspace{250px}
I want to be further down on the page :(

\vspace{250px}
Haha! Sucker :D
\end{document}

Whhhhhhy????

How can I get the first \vspace to work, just like the second one?

  • 92
    I wish every example came with such an instructive picture. :-) – lockstep Nov 1 '11 at 21:45
183

The space added by \vspace is deleted at the beginning of the page, as you have seen. The command \vspace* adds the space that is not deleted.

\documentclass{article}
\begin{document}

\vspace*{250px}
I want to be further down on the page :(

\vspace{250px}
Haha! Sucker :D
\end{document}
  • 34
    Damn! Three answers in like, 30 seconds :) Thanks! I'll give you the accepted credit since you seem to be the one lowest on funds. – Speldosa Nov 1 '11 at 21:32
  • Funds? Me not understand why the need for currency – nilon Feb 24 '17 at 14:26
  • Do you know a way to do this that math stack exchange will recognize? – Kyle Delaney Sep 26 '17 at 14:49
  • 1
    This may be the wrong place to say this, but it's bulls*** like this that makes me hate LaTeX. Thanks for the tip! – kontextify Nov 24 '17 at 9:49
  • 5
    @kontextify The space at the beginning of a page is deleted for a reason. Normally space is used to separate blocks of text (like an equation and the following text); when a new block starts a page, this separation is no longer needed – Boris Nov 30 '17 at 6:34
57

Spaces at page breaks are swallowed, as usually one doesn't want them. TeX starts counting from zero, so the first page is after a page break. :)

The solution is to issue \vspace* instead of \vspace.

I recommend not to use px which is not what one with a CSS background would expect. Use rather cm, mm or in or multiples of \baselineskip:

\vspace*{2cm}
\vspace*{4\baselineskip}

The default value of 1px is just 1bp (where 72bp = 1in); it's a special unit of measure that can be tailored for specific applications concerning on-screen only documents. For example, to make a document as wide as a 1200 pixel screen at 96dpi, one can pass geometry a paper width of 1200px by

\pdfpxdimen=1in % just to start the computation
\divide\pdfpxdimen by 96 % 96 px are now 1in
\geometry{paperwidth=1200px}

For "paper" document, this is irrelevant.

  • Well, that was almost embarrassingly easy :P Thanks for the quick reply! – Speldosa Nov 1 '11 at 21:29
  • @Speldosa This is not easy: knowing that the first page is like the other as far as page breaks are concerned is not very intuitive at the beginning. – egreg Nov 1 '11 at 21:39
  • That's for sure. I've been using LaTeX for over a year now and I still feel like a beginner :) Thanks for the elaboration on px vs other units. You wouldn't happen to have any link to any kind of resource where I can learn more? – Speldosa Nov 1 '11 at 21:52
  • @Speldosa About px there's not much around, you can look at texdoc pdftex, where it's explained on page 32. – egreg Nov 1 '11 at 21:55
35

In addition to the flurry of \vspace* suggestions, you could also issue a "nothing" command to allow subsequent \vspaces to typeset as expected. This "nothing" command could be an \mbox{} (an empty box) or \null, provided that you leave an empty line (or \par) to be in vertical mode.

More specifically, you would need

\documentclass{article}
\begin{document}
\mbox{}% or \null; note the blank line below. Alternative, add \par on this line.

\vspace{250px}
I want to be further down on the page :(
\end{document}

although \null is a better choice - it does not require the blank line or even \par.

  • I actually tried using a \mbox{} command without any success. Does that compile as it should for you? – Speldosa Nov 1 '11 at 21:38
  • @Speldosa: I've added some more content to show exactly what I mean. – Werner Nov 1 '11 at 21:40
  • 5
    \mbox does \leavevmode, so adding a \baselineskip to the specified dimension; \null is better (and doesn't even require a blank line after it). – egreg Nov 1 '11 at 21:41
  • What the...Ah. I forgot to add the blank line when I tried it out. It compiles fine now. – Speldosa Nov 1 '11 at 21:43
  • @egreg: Good observation! – Werner Nov 1 '11 at 21:51
4

did try to post this as a comment, but it didn’t fit, not even in a more succint version... :-(

I chanced upon this question, and, while reading the answers and the comments, I thought that it would be worthwhile to add a reference to the following two questions:

Note, besides, that @egreg’s comment, that recommends to avoid using \mbox{}, and to use \null instead, is not entirely correct: it is true that \null doesn’t require to be followed by a blank line (or by a \par); it is true that it is much more efficient, in that it avoids starting a new paragraph and adding one level of boxing; but it is not true that the two solutions yield different results. Indeed, both end up adding to the main vertical list the following things (omitting some items for simplicity):

  • the \topskip glue;

  • a zero-height \hbox;

  • the skip specified in the argument of \vspace;

  • the \parskip glue;

  • the \baselineskip glue;

  • what comes next.

(The above claim can be easily verified with \showlists.)

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.