How to center an image without name (quarto)?

Hello! I am using typst with quarto. When I create an image, such as

![](/path/to/image)

This inserts image not centered, but if I will add name

![any_name](/path/to/image)

It will be centered, but with label “Figure X: any_name”.

I want centered image without name. I know that one can add {fig-align: center}, but I don’t want to add it each time I create an image wihtout name. So is it possible to somehow set that in typst-template or quarto initial settings?

I have no idea how quarto works. From your description, I guess the first snipped will be converted to a simple Typst image. In your Typst template you can set the alignment for all images with:

#show image: set align(center)

I think it is probably better to ask quarto related questions first to quarto people as I think there is a bigger overlap of people using both tools.

1 Like

You would need to add a show rule for box, rather than image for Quarto’s output.


#show box: set align(center)

To see why, we need to retain the intermediate Typst file that is being generated. We can do that by to updating the header block like so:

---
title: "some title"
format: typst
keep-typ: true
---

Then, we can see that the following:

---
title: "some title"
format: typst
keep-typ: true
---

## Figure without text

```{=typst}
#show box: set align(center)
```

![]({{< placeholder 100 100 format=png >}})

## Figure with text

![i have text]({{< placeholder 100 100 format=png >}})

will evaluate to (a ton of document style followed by):


...

= Figure without text
<figure-without-text>
#show box: set align(center)
#box(image("fig-center-demo_files\\mediabag\\FiKGhYhhIWJYiBgWIoaF.png"))

= Figure with text
<figure-with-text>
#figure([
#box(image("fig-center-demo_files\\mediabag\\FiKGhYhhIWJYiBgWIoaF.png"))
], caption: figure.caption(
position: bottom, 
[
i have text
]), 
kind: "quarto-float-fig", 
supplement: "Figure", 
)

where the placeholder shortcode generates the two temporary figures fig-center-demo_files/*.png based on the name of your file, here fig-center-demo.qmd.

Hello! Thank you very much for answers. The information about that the image is displayed in the box instead of figure helped me a lot. Some said that I can use show box rule with center aligning, but that will align every single box in the document (which will lead for table of contents to become a mess), so this way is good, but one need to make rule logic more complex.

So, I found an idea:

show box: it => {
  if it.body.func() == image {
    align(center)[#it]
  } else {
    it
  }
}

This will center align only images. Thank you for the answers!

1 Like

You can do

#show box: it => if it.body.func() != image { it } else { align(center, it) }

or

#show box: it => {
  set align(center) if it.body.func() == image
  it
}