How can I use different page number locations on alternating pages?

#set page(height: auto)

// Starting from left:
// #set page(header: context {
//   let page = counter(page).get().first()
//   let body = if calc.odd(page) [odd ] else [even ] + str(page)
//   let alignment = if calc.odd(page) { left } else { right }
//   align(alignment, body)
// })

// Starting from right (book style):
#set page(header: context {
  let page = counter(page).get().first()
  let body = if calc.odd(page) [odd ] else [even ] + str(page)
  let alignment = if calc.odd(page) { right } else { left }
  align(alignment, body)
})

#range(5).map(_ => pagebreak()).join()

This can be simplified to:

#set page(header: context {
  let page = counter(page).get().first()
  align(if calc.odd(page) { right } else { left })[#page]
})

I have a feeling that this might be achieved in some even easier way, but nothing else comes to mind.

1 Like