TransWikia.com

Why negative vspace skips less space than specified in LaTeX

TeX - LaTeX Asked on July 25, 2021

I have code like this:

documentclass{article}

usepackage[a4paper,left=0pt, right=0pt, top=50pt, bottom=0pt]{geometry}
usepackage{show frame}

begin{document}
vspace*{-50pt}
Hello!
end{document}

I skip the amount of space that equals the top margin. So I expect the text to appear at the top of the page with no margin at all. However it seems like the vspace skips less space than expected. In fact if I write vspace*{-5pt} it moves the text in the opposite direction. Why does it happen and how to specify skipped/added space precisely? I do need this 50pt margin at the top of the page but sometimes I need some content to protrude into the margin on some pages. And I need to be able to specify spacing accurately.

One Answer

add showoutput

with no space you get

...glue(topskip) 3.05556
...hbox(6.94444+0.0)x597.50787, glue set 557.23004fil
....hbox(0.0+0.0)x15.0
....OT1/cmr/m/n/10 H
....OT1/cmr/m/n/10 e
....OT1/cmr/m/n/10 l
....OT1/cmr/m/n/10 l
....OT1/cmr/m/n/10 o
....OT1/cmr/m/n/10 !

so topskip is set to make the baseline of the first line 10pt from the top, so 3pt is added with the rest coming from the height of H.

With vspace*{-5pt} you get

...glue(topskip) 10.0
...rule(0.0+0.0)x*
...penalty 10000
...glue -5.0
...glue 0.0
...glue(parskip) 0.0 plus 1.0
...glue(parskip) 0.0
...hbox(6.94444+0.0)x597.50787, glue set 557.23004fil
....hbox(0.0+0.0)x15.0
....OT1/cmr/m/n/10 H
....OT1/cmr/m/n/10 e
....OT1/cmr/m/n/10 l
....OT1/cmr/m/n/10 l
....OT1/cmr/m/n/10 o
....OT1/cmr/m/n/10 !

as the first item is not text you get the full 10pt of topskip then the -5pt so a total of 5pt. So, as you say, the negative space causes a larger space above the text.


So in short, vspace*{xxx} will move the content the distance xxx from the position it would be in with vspace*{0pt}. The position it is with no vspace* is (for reasonable sized first lines) the same as you get with vspace{-height of first line of text}

Answered by David Carlisle on July 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP