Delay placement of a figure?

I was wondering if it was possible to delay a command, so it takes effect several pages later in the document. Specifically, I would like to place a figure several pages later than in appears in the source.

For example, in the following I would like the figure occur on the second or third page:

#figure(
    placement:bottom,
    [#square(fill: blue, size: 4cm)],
    caption: [Somewhere in the middle.])

#lorem(3000) // A several page text document. 

My goal is to control the position of the figure, without interspersing the document text and typst commands

Thanks!

Hello, my first thought was to use place.flush():

Asks the layout algorithm to place pending floating elements before continuing with the content. Place Function – Typst Documentation

Screenshot

It’s probably more toward the opposite of what you’re asking for, but I’m sure this also dawned on others looking at the post.

Yes, place.flush() is essentially of the opposite of what I would like to do.

1 Like

How do you intend to control the position of the figure in the document? I mean what would the ideal solution look like in code?

1 Like

If by “occur” you mean just visually, then do:

#let some-figure = figure(
  placement: bottom,
  square(fill: blue, size: 4cm),
  caption: [Somewhere in the middle.],
)

#lorem(3000) // A several page text document.

#some-figure

But I think any granularity in “place on page n” is impossible. You can do out of document flow conditional placement with page.background. If it doesn’t naturally place into the exact place, then it’s probably never will, gotta place it manually.

Because of the lack of other good solutions, here is a dubious one. You can ask meander to make a layout like this: one or more full pages, then a page with a placed figure on the bottom. And the text flows through those pages.

#import "@preview/meander:0.4.2"

#meander.reflow({
  import meander: *
  container()
  pagebreak()
  placed(bottom, figure(rect(width: 100%, height: 8cm), caption: [Caption]))  
  container()
  content[
    #set par(justify: true)
    #lorem(1500)
  ]
})

This text comes after that block.

1 Like