How to center caption but left align the text inside?

How can I align the caption of a figure with the center of its corresponding image and at the same time have the text inside the caption be left-aligned? I am currently using this show-rule to left-align both the caption and the text:

#show figure.caption: set align(left)

How can I now center the caption while keeping the text inside left aligned?

I found the following solution:

#show figure.caption: it => {
  align(box(align(it, left)), center)
}

This sets the alignment of the caption to left-bound inside the box but then centers the box in relation to the figure. If anybody knows of a better solution, please feel free to comment.

2 Likes