How to have page number appear on all 4 corners of each page?

Hi, I’m trying to have page numbers appear on all 4 corners of my pages. (If you’re wondering why I’m making such a bizarre design choice… it’s to make it easier to navigate the document while zoomed in on a tablet or phone)

I don’t have any fancy existing page setups except #set page(numbering: "1") which I will no longer be using.

What I have come up with so far is

#let page_num = context counter(page).get().first()
#set page(header: page_num, footer: page_num)

This has given me page numbers on the two corners on the left.

Then I saw this example in the documentation that has the content of the header parameter as a list:

#set par(justify: true)
#set page(
  margin: (top: 32pt, bottom: 20pt),
  header: [
    #set text(8pt)
    #smallcaps[Typst Academy]
    #h(1fr) _Exercise Sheet 3_
  ],
)

#lorem(19)

Naturally I tried to mimic it:

#let page_num = context counter(page).get().first()
#set page(header: [page_num, page_num], footer: page_num)

Not what I was expecting! The compiler error message is hilarious, though:
Misspelling: The word "page_num" seems to be misspelled

How do I do this correctly?

You were nearly there. The main addition was to add a horizontal space that would “push” the two numbers as far apart from each other as they can go (h(1fr)). See Fraction for details about the 1fr.

#let page-num = context here().page()

#set page(
  "a8",
  header: [#page-num#h(1fr)#page-num],
  footer: {
    page-num
    h(1fr)
    page-num
  }
)

= Heading
#lorem(20)


In Typst these square brackets [] tell the compiler that the text within should be parsed as markup mode. This is the default mode but functions (like page( here) are called from code mode so you have to switch back to markup by using the brackets.
In my example I used curly brackets {} for the footer. Everything within these is parsed as code. It’s a good choice here because there are only variables or functions getting added to the footer. If there was more text then {} may be more awkward. The important thing to say is that both options work and have different strengths.

3 Likes

Thank you gezepi, this worked wonderfully, and thank you so much for catching my misunderstanding of the syntax!

1 Like