Very new to Typst, but getting to grips with it. I do have a number of questions, but I’ll start with this.
I have managed to set up my page the way I want and have 4 levels of headings. However, in a trial project (recipe book!) headings can get separated from the following paragraph by a page break.
(As I’m new to the forum I can’t post a screenshot!)
In word processor terms, I’d set all headings with “Keep with next” to avoid this. I have gone through all the documentation here on Typst, but can’t see an equivalent.
Can someone please advise how it can be done, other than laboriously going through putting a page break before any heading where it happens?
What you request is the default behavior for headings. If you’re observing this behavior, it’s possible you used a faulty heading show rule which replaced the heading with its body (for example), perhaps in an attempt to customize the spacing from the heading number or some other reason. Make sure to wrap the heading show rule’s output in block(sticky: true)[...] to retain the orphan prevention behavior.
If that doesn’t solve it, you could also be facing a bug, but let us know if that fixes it.
Thank you so much. I’m not sure where the block(sticky: true) goes in the show rules for headings. You are right that I was customising the font sizes and it took me a long time to get it to work at all. What I had was:
seems to work to apply “Keep with next”, but I presume I have the [ in the wrong place to add the (sticky: true), even though I copied it from the “Advanced Styling” section of the tutorial.
It’s true that simply adding a block will do it since headings have a set rule to set any blocks within them as sticky. But for future reference, you can just write #block(sticky: true, it.body) instead of just #block(it.body), i.e. sticky is just a named parameter, whereas the body is a positional parameter.
However, if all you want is to customize font sizes, I’d recommend writing the following instead of that show rule:
#show heading.where(level: 3): set text(16pt, weight: "semibold")
(Addendum: You can write ```typ ``` to highlight your code as Typst syntax.)