How do I repeat a table’s header every page, but not the content?

Hello I am currently writing a templet for my lab report and have come across an issue, the content that I enter shouldn’t repeat every page but the header should.
The part of the code that currently displays the content is:´

grid.cell(colspan: 6, align(left+top)[\ #table(
              stroke: none,
              columns: (1cm, 16cm, 1cm),
              rows: 22.2cm,
              [],[#content],[]
            )])

I would be extremely grateful if someone could help me.

This is the header Picture


and this is how the templet should look like

My code

#set page(width: 21cm, height: 29.7cm)
#set text(size: 12pt)

#let wst_vorlage(
    kompetenz: "",
    name: "Samuel Findenig",
    klasse: "2AHEL",
    werkstatt: "",
    fachlehrer: "",
    seitenanzahl: 1,
    datum: "00.00.0000",
    content: ()
      ) = {
  
        let margin = (
          top: 20pt,
          bottom: 20pt,
          right: 20pt,
          left: 10pt
        )

        let n = 1
        while n < seitenanzahl {
        
          set page(margin: margin)
          set align(horizon + center)

          grid(
        
            columns: (4cm, 2.8cm, 2.8cm, 2.8cm, 2.8cm, 2.8cm),
            rows: (auto, 0.49cm, 0.49cm, 0.49cm, 23cm),
            gutter: 0pt,
            align: (center, horizon), 
            
            stroke:  1pt,
            grid.cell(colspan: 6, [#image("wst1.png")]),
          
                align(left)[#tab *Name*],[*Klasse*], [*Werkstatt*], [*Fachlehrer*], [*Datum*],[*Seite*],
                align(left)[#tab #name], [#klasse], [#werkstatt], [#fachlehrer],[#datum],[#context [#here().page() von #seitenanzahl]],
              
            

            grid.cell(colspan: 6, align(left)[#tab *Übung/Kompetenz *#kompetenz]),
            grid.cell(colspan: 6, align(left+top)[\ #table(
              stroke: none,
              columns: (1cm, 16cm, 1cm),
              rows: 22.2cm,
              [],[#content],[]
            )])

          )
          set text(stroke: black) 
          n = n + 1
        }
      }


#wst_vorlage(datum: "20.11.2024", seitenanzahl: 10, content: (
[
  #lorem(100)
]

))

´´´
1 Like
  • First, note that you don’t need to set the page width and height manually. It’s automatically at A4. For other standardized page sizes you can do e.g. set page("us-letter").
  • Your grid should also not be sized manually, but fraction lengths like 1fr, and auto.
  • Using table instead of grid gives you some saner defaults for tables, like some default inset and stroke.
  • Instead of wrapping your whole content into wst_vorlage, you can use show: wst_vorlage.
  • What you call content is usually called body. It should be a positionial argument (i.e. don’t provide a default value) if you want to use the method with the show rule. Also you would need to use wst_vorlage.with(...).
  • Don’t provide the total page count manually, you can use the final() method of the page counter. Even better, the display() method supports numbering patterns that involve the total page counter! (see below)
  • What you are looking for is the header property of page.

Here is a basic fix:

#let wst_vorlage(
  kompetenz: "",
  name: "Samuel Findenig",
  klasse: "2AHEL",
  werkstatt: "",
  fachlehrer: "",
  seitenanzahl: 1,
  datum: "00.00.0000",
  body
) = {
  set text(size: 12pt)
        
  set page(header: table(
    columns: (3fr, 2fr, 2fr, 3fr, 2fr, 2fr),
    stroke: 1pt,
    [*Name*], [*Klasse*], [*Werkstatt*], [*Fachlehrer*], [*Datum*], [*Seite*],
    [#name], [#klasse], [#werkstatt], [#fachlehrer], [#datum], [#context counter(page).display("1 / 1", both: true)]
  ))

  body
}

#show: wst_vorlage.with(datum: "20.11.2024")

#lorem(1000)
1 Like

Hello Sam and welcome! A good post is a post with a good title, don’t hesitate to rename it with a question, as recommended in How to post in the Questions category.
I can suggest the following title “How do I repeat a table’s header every page, but not the content?”

@jbirnick Thank you for your quick response and recommendations. If I add the header picture like this


table.cell(colspan: 6, [#image("wst1.png)]),

the image always gets really small and the text in the grid is on top of it.

Furthermore my school requires there to be a frame around the body

Hello @Sam1,

I used your approach and the improvement suggestions by @jbirnick and came up with the following. I hope it helps.

#let wst_vorlage(
  kompetenz: "",
  name: "Samuel Findenig",
  klasse: "2AHEL",
  werkstatt: "",
  fachlehrer: "",
  seitenanzahl: 1,
  datum: "00.00.0000",
  body
) = {
  table(
    columns:6,
    stroke: 1pt,
    table.header(
      table.cell(
        inset: 0.5pt,
        colspan: 6, 
        image("wst1.png")
      ),
      [*Name*], [*Klasse*], [*Werkstatt*], [*Fachlehrer*], [*Datum*], [*Seitenanzahl*],
      [#name], [#klasse], [#werkstatt], [#fachlehrer], [#datum], 
      [#context counter(page).display((current, total) => [Seite #current von #total], both: true)],
      table.cell(colspan: 6, align(left)[*Übung/Kompetenz *#kompetenz]),
    ),
    table.cell(
      colspan: 6, 
        align(start, pad(1em, body))
    )
  )
}

#show: wst_vorlage.with(
  datum: "20. Nov. 2024",
)

#lorem(1000)
Result