How to automatically fill the gap caused by figures?

In Latex, the text following the figure will automatically fill the gap like this:

#lorem(500)

#figure(
  image("ph.jpg", width: 50%),
)

#lorem(200)

However, it seems that it wouldn’t in typst by default. Is it possible to do that?

The default in Typst is to put the figure at the position where you put it in the code, but you can configure that using the placement parameter. Of course, you can also change the default placement using a set rule:

#set figure(placement: auto)

Setting the “placement” parameter as “auto” can fill the gap, but the figure will either appear at the top or the bottom, which seems less flexible than Latex. Especially when I have 2 figures together, one goes to the top and the other at the bottom, it looks weird. I guess I have to use a set rule.
Thanks anyway.

It should be similar in LaTeX. Do you have a specific case in mind that works in LaTeX, but not in Typst?

You can insert 2 images like this:

#lorem(500)

#figure(
  image("ph.jpg", width: 50%),
  placement: auto,
)

#figure(
  image("R.jfif", width: 50%),
  placement: auto,
)

#lorem(500)

It looks like:

In Latex it looks like:

Hey @shhuang, I’ve edited your posts to use ```typ ``` for code blocks, which highlights Typst syntax, making them easy to read :slight_smile:


I believe it’s just that Typst has a height threshold for placement: auto (possibly different from LaTeX’s) after which it will start sending figures to the bottom, given we can contrast your sample with this one, which has slightly smaller figures and places one figure after the other:

#lorem(500)

#figure(
  rect(width: 50%, height: 24em, fill: blue),
  placement: auto,
)

#figure(
  rect(width: 50%, height: 8em, fill: red),
  placement: auto,
)

#lorem(500)

Note that you can use placement: top instead of auto to force both figures to be placed together (that allows me to increase the height without consequences in the example above). Just take note of the page they end up in, as that may require some manual adjustment.

1 Like

I think you are right. When I make the figures smaller, they come together at the top. I guess manual adjustment is a better way in this case. Nevertheless, I still wish figures in Typst will have the same behavior as in Latex because it looks more “intelligent” to lazy guys like me hhh. Thanks very much!