What is the proper way of fixing the space between the supplement and the number of a reference and a caption?

The following code showcases the default and adjusted behavior of the “gap” between a figures supplement and its number in text as well as the caption.

#set page(width: 10cm)
#set par(justify: true)
Short line with ref to: @l1 #linebreak(justify: true)

#show figure: align.with(left)
#figure(
  table([Example]),
  caption: [long text wich gets justified and stretches or squishes the caption such that the figures number might appear to close or too far from the supplement],
)<l1>

#show std.figure.caption: it => {
  context [#box([#it.supplement~#it.counter.display()])#it.separator#it.body]
}

#show ref: it => {
  box(it)
}

Short line with ref to: @l2 #linebreak(justify: true)

#figure(
  table([Example 2]),
  caption: [long text wich gets justified and stretches or squishes the caption such that the figures number might appear to close or too far from the supplement],
)<l2>

As you can see in the following screenshot, without modifications the gap between the Supplement and the number will shrink or stretch to justify the line.

As demonstrated this can be fixed with show rules, but they seem overly complex for such a simple goal which, in my humble opinion, should be the default.

Is there an easiery way which I’m overlooking? Is my approach the proper way of doing this?

This is how I do it aswell, I don’t think there is another way

1 Like

I would do it like this too.

Your code can however be simplified like this:

#show ref: box

yep, i realized that, but this is not the bad part ;)

Here’s the hack:

#show figure.where(kind: table): set figure(
  numbering: n => box[Table #n],
  supplement: it => none,
)

In your case, it is merely an aesthetic consideration.
For languages that don’t use a spaces here, or languages that put the supplement after the number, it’s a daily pain about correctness…

Previous discussions:

1 Like

Good idea, but since I need this to work with both tables and images some adjustments to your example are nessessary.
I’ll play around with it some more and see what I like most.
This code won’t be user-facing anyway so it’s not really an issue.

1 Like