How do I make a header extend to the left/right margins?

I have been trying to do slides and need a header for my them. I have tried the page.header parameter, however, the header is not placed covering the margin, which is a thing I want.

I looked on the docs and it said that this is correct behavior, and it gave me an example of how to cover the margins

#set page(
  paper: "presentation-16-9",
  foreground: align(top, header),
)

Which works, but now the content does not know there is a header, So i would need to do some work to make it now go behind the #header on the foreground.

Then, I thought that if i take a page on a show rule like this:

#show page: p => [
  #header
  p.body
]

The body will do everything correctly and i can add margins for the body easily.

However, this does not do anything.

Am I using #show page wrong? Is this intended? Does this have to do with context?

The page element is kind of special. According to the doc below, we can’t use show page rules because they are incompatible with the current layout model.

Note: This doc was added in 2025-12 and won’t appear publicly until Typst 0.15. I found it with the help of How do i use a show rule for the page function? - Search | DeepWiki.

Could you clarify it? Is that the height of the header on each page is different and you want header’s top edge to match page’s top edge and the page’s body come below the header?

Besides, perhaps something like this would suffice.

#let build-header() = {…}
#let pagebreak() = {
  std.pagebreak(weak: true)
  build-header()
}

#pagebreak()
= Page 1

#pagebreak()
Lorem Ipsum

I think @Micaias_Oliveira’s issue is with the horizontal margins. The simplest solution is probably to set explicit margins and manually extend the header area, for example with pad:

#set page(
  margin: 2cm,
  header: pad(x: -2cm)[
    #block(fill: red, width: 100%, height: 3cm)
  ],
)
1 Like

Thank you! This “solves” half of the problem (feels like a hack more than a full solution. But one of the big problems is that the header continues to be only a fixed size. If I want it to be taller, it does not change size.

I tried header-ascent which does change the header size, but does not change the contents adapt to the smaller space.

Here is the code:

#import "@preview/catppuccin:1.0.1": catppuccin, flavors
#import "metadados.typ": * // for shared info

#show: catppuccin.with(flavors.mocha)

#let header = {
  box(
    inset:  (top: 0.5cm, bottom: 0.5cm),
    fill: flavors.mocha.colors.surface0.rgb,
    width: 100%,
    align(horizon, stack(dir: ltr, spacing: 4cm)[
      #image("res/logo-simples.png")][
        #insituicao_mais_abrev
      ])
    )
    v(-1.2em)
  line(length: 100%, stroke: flavors.mocha.colors.text.rgb)
}

#set page(
  margin: 2cm,
  paper: "presentation-16-9",
  header: pad(x: -2cm, header),
)
#set text(font: "CaskaydiaMono NF", lang: "pt", region: "br")

#show page: p => [
  #header
  p.body
]

#align(center+horizon)[
  #box(width: 70%)[
    #strong(text(titulo, size: 30pt))
    
    #align(left)[
    *Aluno:* #nome\
    *Orientador:* #orientador ]
  ]
]

#pagebreak()

= Introdução

This is the result

I want to make the header bigger, but i am not sure if it is possible

(post deleted by author)

(Please make sure you give a minimal working example when possible, I can’t compile the code you gave.)

You can put use a block with height: 100% in the header to take all the available space:

#let header = block(
  fill: red,
  width: 100%,
  height: 100%,
)

#set page(
  margin: (x: 2cm, y: 5cm),
  header: pad(x: -2cm, header),
)

This way the block will have a height equal to the top margin, minus the header ascent.

I agree it’s a bit hacky but it’s not too bad… The worst thing is that you need to know the left and right margin for the pad arguments (trying to get these values with context page.margin is tricky and unreliable unfortunately, see Promote `margin` to a type · Issue #3636 · typst/typst · GitHub).

2 Likes

Sorry for the example, I just pulled it from the file.

So the header takes all space on the top margin? if i want a bigger header i could just make a bigger margin then?

I tested it and it worked!

Final solution

#let header = box(height: 100%)[ ... ]

#set page(
  margin: (
    top: 3cm, // size of your header
    x: 2cm,
    // maybe bottom?
  ) 
  header: pad(x: -2cm, header) // pad.x = margin.x
)
1 Like

(I edited the question title to reflect what’s actually being solved in the thread.)