How to align image (in grid) in footer?

Hello,

I want to include a logo in the footer, but I can’t get it to align properly. It seems like #image() ignores the alignment set above and “sticks out”.

#set page(
  paper: "a4",
  flipped: true,
  margin: (top: 2cm, bottom: 2cm, left: 2cm, right: 2cm),
  footer: context {
    line(length: 100%, stroke: 0.5pt + gray)
    grid(
      columns: (25%, 50%, 25%),
      align: (left + horizon, center + horizon, right + horizon),
      gutter: 1em,
      [Left text],
      [Center text],
      // https://upload.wikimedia.org/wikipedia/commons/f/f8/Typst.svg
      [#image("Typst.svg", width: 80pt)]
    )
  }
)

This is a test page to demonstrate the footer alignment issue.

This is how it looks in the end. The logo in the footer extends beyond the right edge of the horizontal line, while it should align with the line’s end like text does:

Here’s a link to the example.

How can I fix that?

Works as you have set it.

If you display the stroke in your grid, you will see it is not the same width as your horizontal line.

Code:
#set page(
  paper: "a4",
  flipped: true,
  margin: (top: 2cm, bottom: 2cm, left: 2cm, right: 2cm),
  footer: context {
    line(length: 100%, stroke: 0.5pt + gray)
    grid(
      stroke:0.5pt, // Grid Stroke
      columns: (25%, 50%, 25%),
      align: (left + horizon, center + horizon, right + horizon),
      gutter: 1em, // Culprit
      [Left text],
      [Center text],
      [Right Text]
    )
  }
)

This is a test page to demonstrate the footer alignment issue.

image

Try with gutter: 0em and you will see the difference.

image

A few notes:

  • You do not need context (unless you add code that requires it)
  • If you don’t need the grid, you could use horizontal spacing with h(1fr) instead and wrap your image in a box. A streamlined version of your code would become:
#set page(
  footer: {
    line(length: 100%, stroke: 0.5pt + gray)
    [Left text]   
    h(1fr) 
    [Center text]
    h(1fr) 
    box(baseline:0.5em, rect()[Typst Logo])
  }
)

This is a test page to demonstrate the footer #strike[alignment issue].

Thank you very much! I did not think about the gutter…