Hi Oscar, I recommend reading about measure
to figure out how it works. Here’s my code:
Margin calculation
/// Reference:
/// https://typst.app/docs/reference/layout/page/#parameters-margin
#let calc-margin(margin, shape) = if margin == auto {
2.5 / 21 * calc.min(..shape)
} else {
margin
}
Show rule
#show heading.where(level: 1): it => {
pagebreak(weak: true)
set text(
size: 1.6em,
weight: "regular",
)
set align(right)
block(
above: 20pt,
below: 50pt,
context {
let title-content = {
smallcaps([Chapter #counter(heading).display(heading.numbering)])
linebreak()
text(size: 1.3em)[*#it.body*]
}
title-content
place(
dx: calc-margin(page.margin, (page.width, page.height)),
horizon + right,
rect(
fill: black,
height: measure(title-content).height,
),
)
},
)
}
I also modified the chapter numbering to make it work properly. Hope this helps