How to add spacing around figures?

Hi, I am trying to add some spacing around my figures. This seems to not be as simple as it ought to be. I have found this:
https://stackoverflow.com/questions/78622060/add-spacing-around-figure-in-typst
and from there have created the following:

  #let figure_spacing = 6em
  #show figure: it => {
    if it.placement == none {
      block(it, inset: (y: figure_spacing))
    } else if it.placement == top {
      place(
        it.placement + center,
        float: true,
        block(it, below: figure_spacing)
      )
    } else if it.placement == bottom {
      place(
        it.placement + center,
        float: true,
        block(it, above: figure_spacing)
      )
    } else {
      place(
        it.placement,
        float: true,
        block(it)
      )
    }
  }

6em spacing for testing purposes only.

For manual placement to top and bottom, this works great. However, for automatic placement (to top or bottom) this does not work. What do I have to put in the last else case to get proper spacing above the figure if its at the bottom, or below the figure if its at the top?

It’s much simpler. For non-floating figures you can adjust the block element’s spacing parameter:

#show figure: set block(spacing: 6em)

If you want different amounts of spacing above and below the figure, change the above and below parameters instead.


For floating figures, there’s the place element’s clearance parameter:

#show figure: set place(clearance: 6em)
3 Likes

Well, thank you very much! So it is as simple as it ought to be!

I had set the blocks inset before and that had wrecked my tables, so I was looking for a different solution. And I must have overlooked the clearance parameter. Thank you, this works like a charm!