The stickiness of my heading broke and I don't know why

Hello everyone,

I suppose this is similar to this topic but several typst updates later and a fix about this very issue.

I’m in this situation where the heading is an orphan. I don’t understand how this happens since headings are sticky by default…

Just in case, I made sure the headings are sticky : #show heading: set block(sticky: true) but this did nothing.

I also don’t see anything that could break the stickiness in my level 2 heading rule :

#show heading.where(level: 2): it => {
  v(1.5em)
  align(center)[
    #text(
      size: 12pt,
      weight:"regular",
    )[#smallcaps[#it.body]]]
    }

So I don’t know what I am doing wrong here… Do you know what’s going on ?

Thanks in advance !

Hi @qntnlq,

if you use it.body your heading is no longer surrounded by a block, so it can’t be sticky anymore. You need to either use it directly or surround your heading manually with a block again.

#show heading.where(level: 2): set align(center)
#show heading.where(level: 2): it => block({
  v(1.5em)
  text(
    size: 12pt,
    weight:"regular",
  )[#smallcaps[#it.body]]
})
1 Like

Didn’t see that one coming.
It definitely works with #it. So thank you very much, problem solved !

I have a pretty noob question, though : what are the pros and cons of using #it or #it.body ?
I must admit I mostly used #it.body because I’d seen many people use it, without questioning the implications much.

it is the element itself, in this case the full heading (and the name it is just a convention). If you hover over it in the Typst web application or in Tinymist you can see it’s content.

it.body is only the body part of the heading.


The detail that a heading is surrounded by a block is unfortunately currently not visible and you just have to know :(.

I can’t give pros/cons as it depends on what you want to do.

1 Like