How to customize the body of an outline entry?

Hello, I’m using Typst to write my thesis. I’m currently trying to customize my lists of figures. I’d like to write a show rule that changes the body of each outline entry without affecting the indentation, prefix, fill, or page number.

Here’s two things I’ve tried so far. In these examples I’m trying to rebuild the outline entry without modifying its appearance at all (if this works then I’ll replace it.body() with something else). They’re both based on this page on the website, but with it.inner() broken up into its components. As you can see, simply concatenating it.body() with it.fill and it.page() puts undesirable line breaks between all of them. I thought I could fix this by putting them in a horizontal grid, but then the fill isn’t long enough when the body is multiple lines long.

Minimum working example

#show outline.entry: it => link(
  it.element.location(),
  it.indented(
    it.prefix(),
    it.body() + it.fill + it.page(),
  ),
)

#outline()

#show outline.entry: it => link(
  it.element.location(),
  it.indented(
    it.prefix(),
    grid(columns: (auto, 1fr, auto), align: bottom, it.body(), it.fill, it.page()),
  ),
)

#outline()

= a really really really long loooooooooooooooooooooooooooooooooong maaaaaaaaaaaaaaaaaaaaaaaaan

Is there a way to put these three things together in-line rather than as paragraphs or as columns in a grid? How does outline.entry.inner() do it?

Hi @jkunimune,

the problem is it.fill, which is a repeat element and takes the full space. You can restrict it with box(width: 1fr, it.fill) to the available space on the line.

#outline(title: [Default Contents])

#show outline.entry: it => link(
  it.element.location(),
  it.indented(
    it.prefix(),
    it.body() + sym.space + box(width: 1fr, it.fill) + sym.space + sym.wj + it.page()
  ),
)

#outline(title: [Imitated Contents])

= a really really really long loooooooooooooooooooooooooooooooooong maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanaa

I added sym.wj to prevent the page number from standing alone in a newline.

1 Like

Ah, perfect, I understand now. Thank you!

Hi @jkunimune, thanks for your question! If you feel the response you got has sufficiently answered your question, be sure to give it a checkmark :ballot_box_with_check:. This will help others find the solution in the future. Thanks!

Edit: I have marked a response as the solution.