Unwanted space before headings with `set heading`

Why is there a space before headings in the example below? In my app, I have a complex “if” inside the function, but below is the totally boiled-down version that also shows the space.

#set heading(numbering: (..nums) => none)


= Prospective
#lorem(20)

== Sub-Prospective
#lorem(20)

Hi, welcome to the forum!

It’s because when numbering is not none (in you case, it’s a function that returns none, and the function itself is not none), a small space will be inserted between the number and the body.
In other words, = Prospective becomes the following:

none + h(0.3em, weak: true) + [Prospective]

Related issue: Too wide spacing between heading numbering and title in CJK · Issue #5778 · typst/typst · GitHub

Solution A: Returns a negative space

#set heading(numbering: (..nums) => h(-0.3em))

Solution B: Replace if/else with where selectors

#show heading.where(level: 2): set heading(numbering: …)
#show heading.where(level: 3): set heading(numbering: …)
3 Likes