What is the most ergonomic way to set a different margin for single pages?

As per How to get differently-sized header or footer depending on page number? - #8 by laurmaedje I’m aware that there is currently no way to adjust the margins dynamically, but I’m looking for the best way to adjust the margin for single pages (chapters/titles) to one setting and then back to another without having to state the explicit values every time.

I was thinking of adding metadata to these pages like:

#let no-margin-page() = {
  query(metadata.where(value: "nomargin")).any(m => m.location().page() == here().page())
}

Then adding

#metadata("nomargin")<nomargin>

to the titles/chapters.

And then doing something like:

#set page(
  margin: context if no-margin-page() {
      (y: 2.5cm, x: 2.5cm)
    } else {
      (y: 2.5cm, left: 2.5cm, right: 5cm)
    }
)

But I still get "expected auto, relative length, or dictionary, found content". What I’m trying to avoid is repeating:

#set page(margin: A)
// the page
#set page(margin: B)
// another page

all throughout the document. What would be the best way to do that?

To be clear, what’s not possible as I understand, is to change the margins without triggering a page break. If you want particular content on page(s) with different margins, the simplest is

Some content.

#page(margin: 1cm)[
  Some content with different margins.
]

Some content.

You can put this page() call in another function that does more things of course. But you need to choose not only the start but also the end of content that has the special margins.

At least this spares the need to set and reset the margin. I just wanted to make sure I used the solution that currently makes the most sense. Thank you for the input!

1 Like