#how to make section header as page header?
26 messages · Page 1 of 1 (latest)
Use this:
#let document-title = "My Book"
#set page(header: locate(loc => {
let this-page = loc.page()
if this-page == 1 {
[] // don't display anything at the top in the first page
} else if calc.even(this-page) {
h(1fr) // maximizing horizontal space to push it to the right
[*#document-title;*]
} else { // odd page
let headings-after = query(heading, after: loc)
let this-heading = if headings-after.len() > 0 {
headings-after.first()
} else {
none
}
if this-heading != none and this-heading.location().page() != this-page {
this-heading = none // only accept headings from the current page
}
// if there are no headings in the current page, then get the latest one from before
if this-heading == none {
let headings-before = query(heading, before: loc)
this-heading = if headings-before.len() > 0 {
headings-before.last()
} else {
none
}
}
// if there is a heading in this page or a heading before, display it
if this-heading != none {
let number = if this-heading.numbering != none {
numbering(this-heading.numbering, ..counter(heading).at(this-heading.location()))
} else {
[]
}
[*#number #this-heading.body*]
}
}
}))
note that you will have to manually replace "My Book" with your title up there
(it can't detect the title as there's no dedicated element for this, you need to set it through a variable)
shouldn't it be headings-after.first()?
hmm
well
I guess that's up to you
lol
but sure
I'll use that instead
actually
yeah I just thought about it
it'd get headings from other pages
it'd be weird
lol
i mean, headings-after.last() would always give you the last heading of the document, right?
yeah lol
I did the dummy dum there
neuron 1 said something to neuron 2 but neuron 2 was like "sorry i didnt hear you" and that was about it
Tried this but it throws me an error, any help on that?
the error is on this: let headings-before = query(heading, before: loc)
Great observation ; the syntax changed after the latest update
It’s now query(selector(heading).before(loc), loc)
It was done that way to be more consistent (you can use that same selector() syntax on #show rules)
thank you!