How can I robustly place a box exactly on the left edge of each page?

With background:
// Requires context
#let get-margin-left() = if page.margin == auto {
  calc.min(page.height, page.width) * 2.5 / 21
} else {
  page.margin.left
}

#set page(
  background: context {
    place(
      top + left,
      dx: get-margin-left(),
      box(width: 4mm, height: page.height, fill: red),
    )
  },
)
With header:
#set page(
  header: context {
    place(
      top + left,
      dx: 0cm,
      box(width: 4mm, height: page.height, fill: red),
    )
  },
)

1 Like