I would like to display a decorative bar in the header of my document. I have a small image that I want to render multiple times next to each other to create a horizontal image bar. I know that Typst has a For loop, but I don’t realise how to apply this to my problem. When do I know when I can stop because the right edge has been reached?
I guess the pattern function could help you.
I had a very similar question:
This sounds like a job for the repeat
function
The hint to the pattern function helped me:
#let tile = image(
"./images/ornament.png",
height: 8mm
)
#let tile_pattern = pattern(tile)
#rect(
width: 100%,
height: 8mm,
fill: tile_pattern
)
1 Like
The pattern function caused difficulties. The tile was repeated correctly in the header. Unfortunately, this only worked on every second page in the footer. The title was shifted on the faulty pages. After a lot of trial and error, I was able to find a solution based on the repeat function:
#let ornament = repeat(
justify: false,
image("./images/ornament.png", height: 15mm),
)
#set page(
flipped: true,
margin: (top: 21mm, bottom: 21mm, left: 5mm, right: 5mm),
header: align(top, pad(x: -10mm, top: 2mm, ornament)),
footer: align(bottom, pad(x: -10mm, bottom: 2mm, ornament)),
)