I am using a Typst template in Quarto for a report and I want to number my images and tables. I want them to be numbered as Figure 1.1, Figure 1.2 in chapter 1 and as Figure 2.1, Figure 2.2 in chapter 2. Currently, the figures in chapter 2 are numbered as Figure 2.3, Figure 2.4. The first number is correct, but I want the second number to be resetted at the start of each chapter.
I import my typst template in the yaml. In the typst template I use the following pieces of code:
show heading.where(level: 1): hdr => {
counter(figure.where(kind:image)).update(0)
counter(figure.where(kind:table)).update(0)
hdr
}
set figure(numbering: n => {
let hdr = counter(heading).get().first()
let num = query(selector(heading).before(here())).last().numbering
numbering(num, hdr, n)
})
To my understanding, the first piece of code should reset the second number in the figure and table numbering when a new chapter is made by placing a new header.
Hello. These rules do work correctly in Typst. I don’t know what Quarto is, but there is little chance it can compile Typst code, so it shouldn’t matter what you use, what matters is what Typst code is being compiled. Without providing code that doesn’t work, I can’t help. See https://sscce.org/.
To avoid having to manually reset all kinds separately, you can also query for all figure kinds used in the document:
#show heading.where(level: 1): it => {
let kinds = query(figure).map(fig => fig.kind).dedup()
for kind in kinds {
counter(figure.where(kind: kind)).update(0)
}
it
}
This way you don’t need to know that quarto uses different figure kinds (though this of course requires that you actually want to reset all figure kinds).