Page number aligns to the first line when wrapping outline body in a fixed-width box

Hello
I’m trying to customize outline.entry so that the body doesn’t extend into the page number area when it wraps to multiple lines.

To do this, I measure the page number’s width and wrap the body and fill in a box with width: 100% - page-width . However, this breaks the vertical alignment of the page number.

If the title is long and wraps to multiple lines, the page number sticks to the first line of the text, instead of the last line.

    show outline.entry: it => {
        let page-width = measure(it.page()).width
        let body-fill = box(width: 100% - page-width, it.body()+box(width: 1fr, inset: (left: 0.15em, right: 0.15em), it.fill))
        link(
          it.element.location(),
          it.indented(it.prefix(),
            body-fill
            +sym.wj
            +it.page()
          )
        )
    }

image

Is there a way to restrict the width of the body while keeping the page number aligned to the bottom (last line) of the wrapped text?

I could be wrong, however this appears to be a duplicate of How to customize the body of an outline entry?

See also How to modify the styling of outline entries?

2 Likes

I might be missing something, but the solution from this topic doesn’t quite work for me.

Here’s how it looks:
image

It does fix the page number alignment, but my actual goal is to prevent the body text from extending into the page number area when it wraps to multiple lines. So this doesn’t fully solve my problem.

I think a grid works quite nicely for this.

#show outline.entry: it => link(it.element.location(), {
  grid(
    columns: (auto, 1fr, auto),
    align: (auto, auto, right+bottom),
    it.indented(
      it.prefix(),
      none,
    ), {
      it.body()
      sym.space
      box(width: 1fr, it.fill)
    }, {
      sym.space
      it.page()
    }
  )
})
1 Like