I want to create an outline that has a bit of spacing between the fill and the page number. However for multiline entries in the outline I want to have the heading linebreak before that space. The following
#show outline.entry: it => {
link(
it.element.location(),
it.indented(
it.prefix(),
it.body()
+ h(0.5cm) // spacing between heading and fill
+ box(width: 1fr, it.fill)
+ sym.wj // prevent number from ending up on its own line
+ box(width:1cm, align(end, it.page())), // spacing next to the page number (start should align even if page numbers have multiple digits)
),
)
}
#outline()
= This is a heading
== This is also a heading
== This is another very long -- and I mean so long that it stretches more than one line -- second level heading
generates this
where the word “level” should already be in the newline.
Hello and welcome! You could wrap the body + fill inside a box:
#show outline.entry: it => {
link(
it.element.location(),
it.indented(
it.prefix(),
box(
width: 100% - 1cm, // 1cm comes from width of the number box
it.body()
+ h(0.5cm) // spacing between heading and fill
+ box(width: 1fr, it.fill)
)
+ sym.wj // prevent number from ending up on its own line
+ box(width: 1cm, align(end, it.page())), // spacing next to the page number (start should align even if page numbers have multiple digits)
),
)
}
I am not sure though if there is an easier way or why exactly 0.65em seems to be aligned and whether that fails if there is e.g. a different line spacing. So I’ll leave the question open for a few days to see if someone else has an answer to that.
(at this point, the outline.entry.indented() function becomes a bit pointless, I prefer to indent by a fixed amount and put the prefix in a box of fixed width, similar to the page number)
This seems to work because 0.65 is close to the height of text/letters. This breaks when using other fonts with different measurements. What you want there is measure(sym.zws).height (this needs context)