How to insert rectangles on my images without creating new box rows?

Hey, I am writing my bachelors thesis and part of it is analysing images. I want to show certain areas in it without manipulating the image file, so I tried to use this workaround:

#figure(
  grid(
    columns: 2,
    gutter: 0.5em,
    block(
    image("../pic16.png")),
    block(
    image("../pic17.png")),
     place(dy: -82pt, dx:110pt, rect(
                          stroke: 1pt + red,
                          width: 10mm,
                          height: 5mm
                         )),
     place(dy: -90pt, dx:3pt, rect(
                          stroke: 1pt + red,
                          width: 20mm,
                          height: 6mm
                         )),     
     place(dy: -95pt, dx:350pt, rect(
                          stroke: 1pt + red,
                          width: 16mm,
                          height: 6mm
                         )),
  ),
  caption: [Die REM-Aufnahmen zeigen den Querschnitt der Probe, welche bei Raumtemperatur mit Stickstoff und einem Gasdruck von 1,8 bar gespritzt wurde],
)<T2.2_Quer>

The problem I find with this is that it creates more spacing under the image with new box rows, even when I do rows:1 in the figure, see screenshot attached. Figure (Abbildung) 16 has too much spacing after the image whereas Figure 17 has the correct amount.
How Can I create rectangles on top of the image without creating new blank rows?

1 Like

The space below is caused by the place elements creating new grid cells. For debugging you can set a stroke for the grid e.g. stroke: 1pt, to see the empty grid cells.

To group the image together with the place elements in a single cell you can wrap them with curly braces.

#figure(
  grid(
    columns: 2,
    gutter: 0.5em,
    block(
    image("../pic16.png")),
    { // <- Start cell2
      block(
      image("../pic17.png"))
      place(dy: -82pt, dx:110pt, rect(
                          stroke: 1pt + red,
                          width: 10mm,
                          height: 5mm
                         ))
     place(dy: -90pt, dx:3pt, rect(
                          stroke: 1pt + red,
                          width: 20mm,
                          height: 6mm
                         ))  
     place(dy: -95pt, dx:350pt, rect(
                          stroke: 1pt + red,
                          width: 16mm,
                          height: 6mm
                         ))
    }// <- End cell2
  ),
  caption: [Die REM-Aufnahmen zeigen den Querschnitt der Probe, welche bei Raumtemperatur mit Stickstoff und einem Gasdruck von 1,8 bar gespritzt wurde],
)<T2.2_Quer>

P.S. Image is already a block level element, so normally there is no need to wrap them with explicit blocks.

1 Like

Thank you very much. Those brackets are what I was looking for