What's the proper way to center `outline.title`?

The title generated by outline is left-aligned by default. What’s the proper way to center it?

My attempts

Test code
#set page(width: 240pt, margin: 15pt, height: auto)

// #set .. or #show ...

#outline()
= Heading

Method A

The naive method:

#set outline(title: align(center)[Contents])

But no effect:

Method B

From How to center `outline` title? · typst/typst · Discussion #2004 · GitHub in 2023:

#show outline: it => {
  show heading: set align(center)
  it
}

It works, but is it still relevant today? Are there any side effects?

Method C

After checking the source code, I realize that outline.title will be put inside a heading, and come up with the following.

#set outline(title: block(width: 100%, align(center)[Contents]))

Is it suitable to put block and align in a heading?

Method B seems best since it separates presentation and content better.

Method C: every heading is already wrapped in a block. Adding a block around just the title will not work well with heading numbering, if one would want that.

Okay, I’ll go with the B.

The problem originates from the inconsistency in formatting between the outline’s title and regular headings in the main text. (If I were to design the format, I wouldn’t do it.) Therefore, a little complexity is acceptable.

Really?! You mean Typst 0.14?

Please disregard, it does not work.

1 Like