In the typst template I am working on, I want to have the current main chapter on top right of each page (excl. titlepage) with an underline across the page width.
For that, I did follow the example mentioned in the docs: https://typst.app/docs/reference/introspection/query/
This is what I got so far:
set page(
paper: "a4",
numbering: "1",
number-align: center,
header: locate(loc => {
let elems = query(
selector(heading).before(loc),
loc,
)
let header-text = smallcaps[
]
if elems == () {
align(right, header-text)
line(length: 100%, stroke: 0.5pt)
} else {
let body = elems.last().body
header-text + h(1fr) + smallcaps(body)
line(length: 100%, stroke: 0.5pt)
}
}
)
)
However, there are a couple of issue, I don't know how to solve:
-
I don't want this to show up on the title page, the table of contents. Currently it shows up on every page, including the title page. How do I prevent that/filter that?
-
I only want to show top level headings e.g. heading 1. or 2., but not headings like 1.1 or 2.1 or smaller. How do I do that?
-
I would like to decrease the vertical space between the heading text and the horizontal line. How can I do that?
-
There is an edge case when showing the heading following the table of contents. It still shows "TABLE OF CONTENTS" on the page, even tho the table of contents already ended on the previous page. Instead I would expect to see "INTRODUCTION".
Can someone help me with these issues?