Problems
There are several problems in the code you provided:
- The numbering function is ambigous: The
level: 1
numbering is set to "A.1."
but it seems that "Chapter 1."
or "Appendix"
is expected here.
- The numbering part
Appendix A
should not appear in the title content
Solutions
Step 1. Setup heading numbering properly
First of all, I recommend using the numbly
package to construct numbering functions in a convenient way. Here we can still construct it manually:
#set heading(numbering: (..ns) => {
let ns = ns.pos()
if ns.len() == 1 {
return "Chapter " + numbering("1.", ..ns)
}
return numbering("1.", ..ns)
})
Put this code at the begining, and replace "Chapter " + numbering("1.", ..ns)
with "Appendix " + numbering("A.", ..ns)
and return numbering("1.", ..ns)
with return numbering("A.1.", ..ns)
and place it before the appendix. Then remove all the former #set heading(numbering: "x.x")
. Now you can remove the Appendix A
from your appendix heading.
Step 2. Fix the counter
You will notice that the Appendix now starts from C
in the example document. You can reset the heading counter by adding the following row before the appendix:
#counter(heading).update(0)
Step 3. Misc.
The custom heading counter(heading).display(it => text(1em, weight: 700, block([Chapter #it])))
can be replaved with a simple counter(heading).display()
. If the font weight or size setting is not working properly, I recommend using set text
instead of text(...)
Setting outline.indent
to auto
would make the next level heading align to the end of the numbering, which might be a bit annoying, so you may set it to 1em
or some other value you like.
Modified Example
In case that you wish to use it just by doing copy-paste
#show outline.entry.where(level: 1): it => {
v(12pt, weak: true)
strong(it)
}
#outline(title: [Table of Contents #v(1.5em)], depth: 4, indent: 1em)
#show heading.where(level: 1): it => {
if it.at("label", default: none) != <bibliography> {
context counter(heading).display()
h(7pt, weak: true)
}
text(1em, weight: 700, block([#it.body]))
}
#set heading(numbering: (..ns) => {
let ns = ns.pos()
if ns.len() == 1 {
return "Chapter " + numbering("A.", ..ns)
}
return numbering("1.", ..ns)
})
= Introduction
== Introduction
This is the introduction.
= Background
== Background
This is the background.
#counter(heading).update(0)
#set heading(numbering: (..ns) => {
let ns = ns.pos()
if ns.len() == 1 {
return "Appendix " + numbering("A.", ..ns)
}
return numbering("A.1.", ..ns)
})
= Code Snippets
== Code Snippet 1: some Code
```py
print("Hello World")
```
= Additional Information
== Additional Information 1: some Information
This is some additional information.