How to use a pattern image as the page background?

I would like to simplify the answer by providing some “alternatives”:

#let img = circle(radius: 15pt, fill: green.transparentize(70%))

// Option 1
#set page(fill: pattern(img))

// Option2
// #set page(background: box(
//   width: 100%,
//   height: 100%,
//   fill: pattern(img)
// ))

#lorem(300)

#lorem(100)

#lorem(200)
Output

Note that semantically, you would choose box() over rect() in this case. And by default, rect() is visually visible (draw a rectangle), while box() is not.

If you want to add, for example, a monotone background color, then for the image pattern you would have to use background: box(fill: pattern(img)) approach. But if the default white background color is fine (background is drawn on top of the fill, BTW), then you can use a more compact fill: pattern(img) approach.

You can see that the additional box wrapping is just a “workaround” to use fill: pattern() when the page.fill is busy/not available.

Additionally, you might find useful the image.fit parameter.

2 Likes