How to make (justified) list items fill the entire width?

This is Paragraph justification sometimes doesn't use the full page width · Issue #5472 · typst/typst · GitHub. Add #h(1fr) to any list item. Although sometimes, it doesn’t help.

This is too overcomplicated for what it does. You can do this in 3 neat lines:

#show list.item: it => {
  let children = it.body.at("children", default: ())
  if children.at(-1, default: none) == h(1fr) { return it }
  list.item(it.body + h(1fr))
}

The it.body.at("children", default: ()) idea is from How to avoid numbering subfigure captions when using legal numbering?.

Or in 2 with yet another <processed> hack:

#show list.item: it => {
  if it.has("label") and it.label == <processed> { return it }
  [#list.item(it.body + h(1fr))<processed>]
}

Since you can’t reference list items by default, it’s not a big deal, especially if labels are not used for lists.

1 Like