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'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?

share|improve this question
22  
I wish every example came with such an instructive picture. :-) –  lockstep Nov 1 '11 at 21:45

3 Answers 3

up vote 49 down vote accepted

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}
share|improve this answer
9  
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

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.

share|improve this answer
    
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

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.

share|improve this answer
    
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
4  
\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

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.