I would like to have a footer in my document. The footer should consist of a text and the page number, separated by a pipe symbol. On odd-numbered pages, the page number should be on the right side, and the entire footer should be right-aligned. For example:
lorem ipsum | 45
On even-numbered pages, the footer should be left-aligned, and the page number should be on the left:
46 | lorem ipsum
I would like to set the displayed text differently on each page.
Thank you very much for your answer. It solves one half of my problem. The other part is that I want to place an additional text next to the page number. I would like to be able to redefine this text per page.
The footer text should be defined individually for each page. I don’t know the best way to do this. Do you set a variable for this? Do you call a function?
I’ve come this far now. The pseudo code is only intended to give you an idea of what I have in mind:
#set page(
width: 10cm,
height: 5cm,
footer: context {
let footer-text = [footer-text]
let val = counter(page).get().first()
if calc.even(val) [
#counter(page).display("1") | #footer-text
]
else [
#h(1fr) #footer-text | #counter(page).display("1")
]
},
)
= Page 1
// pseudo code:
// footer-text = [footer text for page 1]
#pagebreak()
= Page 2
// pseudo code:
// footer-text = [footer text for page 2]
In any case, although you have provided a bit more insight, it is still unclear what means you would like to use, which would help suggesting a more complete solution… and avoid duplication.
A working solution, which involves state (avoids using a heading, which would have been showing in the outline by default).
Code (solution with `state`)
// Example using state
#let footer-text = state("footer-text", "oops we forgot to set the text")
#set page(
width: 10cm,
height: 5cm,
footer: context {
let val = counter(page).get().first()
if calc.even(val) [
#counter(page).display("1") | #footer-text.get()
] else [
#h(1fr) #footer-text.get() | #counter(page).display("1")
]
},
)
= Page 1
This page shows the default footer as we didn't set it.
//#footer-text.update([footer *text* for page 1])
#pagebreak()
= Page 2
#footer-text.update([footer _text_ for page 2])
#pagebreak()
= Page 3
#footer-text.update([footer _text_ for page 3])
#pagebreak()
= Page 4
This page still shows the footer from page 3 because we forgot to change it.
//#footer-text.update([footer _text_ for page 4])
For page specifically, if no custom numbering is needed, it can be skipped in the .display(). For heading, you probably want something other than "1.1", but the same thing applies.