How to reference a Figure with modified Padding?

To improve the layout of my document I want to increase the space between the last line of text and the beginning of an image or table. I tried adding padding to the figures, but I encountered some problems regarding the combination of the padding and referencing the figures:

Consider this example:

#outline(
  title: [Images],
  target: figure.where(kind: image),
),

#lorem(50) @myfigure #lorem(50)

#figure(
  image("images/image.svg", alt: "this is an image", width: 75%),
  caption: [this is an image],
)<myfigure>

#lorem(50)

As far as i know, there are different options to add padding to this figure:

  1. #pad(
      y: 7.5pt,
      figure(
        image("images/image.svg", alt: "this is an image", width: 75%),
        caption: [this is an image],
      ),
    ) 
    

    Using this option, there is no way to add the reference <myfigure>. It is not possible to add a reference to a padding (Error: cannot reference pad) and it is not possible to add a reference to a figure inside of a padding (Error: expected comma)

  2. #figure(
      pad(
        image("images/Bussysteme.svg", alt: "this is an image", width: 75%), 
        y: 7.5pt,
      ),
      caption: [this is an image],
    )<myfigure>,
    

    Now the reference works, but the padding is only around the image, not around the whole figure, including the caption. The caption still is to close to the text and further away from the image.

  3.  #figure(
       pad(
         image("images/image.svg", alt: "this is an image", width: 75%), 
         top: 3pt,
       ),
       caption: pad([this is an image],bottom:3pt),
     )<myfigure>,
    

    The padding works and the reference works as well, but the padding of the caption is now included in the outline and destroys the layout there.

Is there a different way to combine padding with references?

There is indeed a very simple way to adjust the spacing around the figures. As figures are block elements, you can make use of the spacing, above and below fields of the block element. To do that, define a show-set rule on figures:

#show figure: set block(spacing: 1.2em + 3pt)

The default value of the spacing is 1.2em, so to increase it by 3pt, you can just add them together. You can of course also set it to any other value, so just play around with it!

Alternatively, you can also use the first approach you mentioned (though I would prefer the above). The label can then still be attached if you put the figure in markup mode, as the syntax with <...> only works there:

#pad(y: 7.5pt)[
  #figure(
    image(...)
    caption: [this is an image]
  ) <myfigure>
]
1 Like

Hey @sereksim, welcome to the forum! I’ve updated your post title to better fit our guidelines for question posts: How to post in the Questions category

Make sure your post title is a question you’d ask to a friend about Typst. :wink:

1 Like

Thanks for your answer! The show-set-rule would apply to all figures, while the approach with padding is linked to one specific figure, right?

Correct! However, you can also scope show rules to single figures:

#[
  #show figure: set block(spacing: ...)
  #figure(...) <myfigure>
]