`0fr` cancels vertical spacing but `0em` doesn't. Why?

I’m trying to typeset a header with a horizontal line. The default spacing between text and line is big so I’m trying to cancel it. I tried v(-1em), but that might break when fonts, page sizes and other circumstances change.

I randomly found that a v(0fr) cancels the spacing but v(0em) doesn’t. Why?

https://typst.app/project/rCTOEj82zjiDuzCqvX3HV6

What’s the standard way to typeset such headers?

The “right way” to cancel the unwanted spacing between paragraphs (other than with #set par(spacing: 0pt)) is to use zero-size weak spacing:

#set page(header: [
  Hello
  #v(0pt, weak: true)
  #line(length: 100%)
])
World

It looks like fractional spacing (0fr) also has the property of collapsing adjacent paragraph spacing like weak spacing does… I guess it makes sense: when spacing items with v(1fr) above and v(2fr) below for example, you don’t want inter-paragraph spacing to interfere with the 1-2 ratio…

2 Likes