Hi, I’m new to Typst and cannot find a way to properly apply a specific customization to headings. I’m trying to format them into the following:
TITLE [number in Roman]
Title text
As an output example it should give something like this:
TITLE I
The first title
Content, content, content, ....
TITLE II
A second title
More content, content, content, ....
TITLE III
Another title text
Even more content, content, content, ....
Both “TITLE [number]” and “Title text” must be centered (the preview is not showing them center aligned even with explicit html code) and in different lines.
I could find on the forum several examples to accomplish almost everything I want (e.g., the following topics: 1, 2, 3, and so on).
However they all suppose a heading left-aligned. When I tried to center align, both “TITLE [number]” and “Title text” get shifted to the right. With the following code it can be replicated:
#set heading(numbering: it => {
set align(center)
set text(14pt, weight: "bold")
numbering(upper("Title") + " I", it)
})
= Test 1
Content
= Test 2
Content
The closest I could get to what I want was with the following:
#show heading.where(level: 1): it => {
text(size: 14pt,
weight: "bold",
[
#set align(center)
#upper("Title") #counter(heading).display("I")\
#it.body
#v(1.5em)
])
}
= Test 1
Content
= Test 2
Content
It then shows TITLE N in every heading. I lack enough knowledge to figure out how to replace the “N” with the actual number in roman format.
Finally I feel I must give some constructive criticism. One of the key points of Typst, related to LaTeX, was the aim to be way easier as a result of its modern syntax. However, a task so simple as customizing a heading with some given inputs became a challenge. In conclusion, IMHO Typst failed hard here. It could be as simple as (prefix, number format, suffix, level, [text]) with some options. Maybe it is and I was just unable/unlucky to find it.