How to change figure caption justification?

Is there an easy way to change the justification of all figure captions from the (it seems) default centred justification, to left- or full-justification?

#show figure.caption: it => {
  set align(left)
  it
}

and

#show figure.caption: it => {
  set par(justify: true)
  it
}

Thanks! By now I had figured out that it works with

#show figure.caption: set align(left)

but could update my question because of a server maintenance.

What difference does the it => {} operator make?

There is no difference. Actually your code is a short form of show: it => { set ...; it }

There actually is a difference, as only when using a show-set rule, the behavior can be changed later in the document again.

#show figure.caption: set align(left)
...
#show figure.caption: set align(center)

Trying to do the same in the “long form” won’t work, as the inner-most show rule (i.e. the bottom one) is applied first. Therefore, if you have something like this

#show figure: it => {
  set align(left)
  it
}

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

#figure(...)

you can imagine it to be evaluated first to this

#show figure: it => {
  set align(left)
  it
}

#{
  set align(center)
  figure(...)
}

and then to this

#{
  set align(center)
  set align(left)
  figure(...)
}

The final alignment is now still left, even though it should have been overridden to center.

4 Likes

Hey @Rene_Skuk! I’ve changed your question post’s title to better fit our guidelines: How to post in the Questions category

For future posts, please make sure your title is a question you’d ask to a friend about Typst. :wink:

1 Like