How to display "Chapter X" above level 1 heading name?

When I type a new depth 1 heading e.g. = Discussion , I want to create something that looks like this:
image

Here is the code I currently have:

// Pagebreak on new chap start
#show heading.where(level: 1): it => {
  set text(28pt)
  pagebreak(weak: true) + it
}

which results in simply:

image

I’m not sure how to extract the chapter number (e.g. 7, in this case) from it

You can get the heading number from the counter(). And if you only want the actual title of the heading, you can access this with it.body.

The show rule below should be close to your requirements. You can still change the font sizes (or other properties) by wrapping “Chapter N” in the text() function. Ideally you would use a relative size, e.g. 0.9em to automatically scale the annotation “Chapter N” with the font size of the heading.

#set heading(numbering: "1.1")

#show heading.where(level: 1): it => block[
  Chapter #counter(heading).display()
 
  #it.body
]

= Discussion
2 Likes

Hello. The image shows 2 text parts that use different font size, while you’re only specifying one. Which one is supposed to be 28 pt? Do you need to have both of these texts appear on the same page?

#set heading(numbering: "1.1")
#show heading.where(level: 1): set text(28pt)

#show heading.where(level: 1): it => {
  block(sticky: true, below: 2em)[Chapter #counter(heading).display()]
  text(1.5em, it.body)
}

// #show heading.where(level: 1): it => {
//   block(sticky: true, below: 1.5em, {
//     text(0.65em)[Chapter #counter(heading).display()]
//   })
//   it.body
// }

= Discussion

image

If you are using pagebreak, then I guess you don’t need sticky, then you can use this:

#set heading(numbering: "1.1")
#show heading.where(level: 1): set text(28pt)
#show heading.where(level: 1): it => {
  pagebreak(weak: true)
  block(below: 2em)[Chapter #counter(heading).display()]
  text(1.5em, it.body)
}

// #show heading.where(level: 1): it => {
//   pagebreak(weak: true)
//   block(below: 1.5em, text(0.65em)[Chapter #counter(heading).display()])
//   it.body
// }

= Discussion
2 Likes