I'm using typst 0.11.1. How do you add spacing between figures, and the subsequent text?
If captions become very long, it can be hard to see where it ends, and the surrounding text begins. Example:
#lorem(50)
#figure(block(width: 100%, height: 10em, fill: green), caption: [Shrek green. #lorem(35)])
#lorem(70)

Where is the option to add padding around a figure?
The figure function inherits from the block function. You can therefore set the default block inset for figures using the following show rule:
#show figure: set block(inset: (top: 0.5em, bottom: 2em))
This code adds 0.5em padding above figures, 2em padding below as was asked, and no padding to the sides.

Update:
The previous solution was leaving blanks at the places where the figure was originally placed before floating. The Github user eltos has created a better rule (requires Typst >0.12.0):
#let figure_spacing = 0.75em // Additional spacing between figures and the text
#show figure: it => {
  if it.placement == none {
    block(it, inset: (y: figure_spacing))
  } else if it.placement == top {
    place(
      it.placement,
      float: true,
      block(width: 100%, inset: (bottom: figure_spacing), align(center, it))
    )
  } else if it.placement == bottom {
    place(
      it.placement,
      float: true,
      block(width: 100%, inset: (top: figure_spacing), align(center, it))
    )
  }
}
#lorem(20)
#figure(block(width: 100%, height: 10em, fill: green), caption: [Shrek green. #lorem(35)], placement: top)
#lorem(10)
#figure(block(width: 100%, height: 10em, fill: green), caption: [Shrek green. #lorem(35)], placement: none)
#lorem(10)
#figure(block(width: 100%, height: 10em, fill: green), caption: [Shrek green. #lorem(35)], placement: bottom)
#lorem(50)

Old Answer (produces blanks between paragraphs)
in Typst 0.13 you can use the following show rule to add some top and bottom spacing around each figure:
#show figure: f => {[#v(2em) #f #v(2em) ]}
#lorem(50)
#figure(block(width: 100%, height: 10em, fill: green), caption: [Shrek green. #lorem(35)])
#lorem(70)

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With