How can I create a header with a line under the content?

Good morning to everyone, I would like to create a header with a text on the left, page number on the right and a line below, I tried for some days but couldn’t… I managed to write text and page number but not the line or only the line, but not both. Please help

Hi @Alberto1, welcome and thank you for your question! I have changed your post’s title to bring it in line with the question guidelines and thus make it easier to find in the future:

Good titles are questions you would ask your friend about Typst.

I also added the header-footer tag.

The most common way would be to use a grid for that:

#set page(
  header: {
    grid(
      // this grid fills the whole width of the header
      columns: (1fr, 1fr),
      // the left and right content are aligned correctly
      align: (left, right),
      [left],
      [right],
      // under the first and only row, there's a line
      grid.hline(),
    )    
  },
)

This is of course only a very basic example; you’ll need to set the inset so that the line does not overlap the text, and the page counter for the page number.

Thank you but this way the text size is the same of the first letter of the main text, I would like to set it at 10pt and write the main text with a different size. Some time ago it worked this way but now it doesn’t, I don’t know way but I have the same problem:

#set page(header: context [Chapter 1 #h(1fr) #counter(page).display("1")] + line(length: 100%))

I think that just means that you need to set the header’s font size. If you write e.g.

#set page(header: [...])

#set text(20pt)

...

The header will just be 20pt tall, because the whole document (or the whole run of pages) has that font size. There used to be a bug that would resolve header and footer styles incorrectly, but that was fixed. For example:

#set page(header: [...])

#lorem(40)

#set text(20pt)

// long enough to go to the next page
#lorem(1000)

In earlier versions, that would have used different font sizes for the headers on different pages – maybe you relied on that?

That works too, and what I wrote applies to it too. You just need to set the font size directly if it’s not what you want:

#set page(header: context {
  set text(10pt)
  [Chapter 1 #h(1fr) #counter(page).display("1")]
  line(length: 100%)
})

As an aside, it’s always good to include information like that in the original post, and what about it doesn’t work.

This is the solution! Thank you very much!