Header in my template looks like this:

I want to make text in header row aligned to the center, while other rows remain left-aligned. But I just can’t make it work. Below is the code with all my attempts at it:
show figure.where(kind: table): it => {
//None of code below works :(
show table.cell.where(y: 0): set align(center + horizon)
show table.header: set align(center)
show table.header: set table.cell(align: center + horizon)
show table.cell.where(y: 0): set table.cell(align: center + horizon)
block(width: 100%, inset: 0pt, it)
}
// this works on header rows for some reason
show table.cell.where(y: 0): set text(weight: "bold", style: "italic")
// This also doesn't work.
show table.cell.where(y: 0): set align(center)
// This aligns all text in table
set table(align: left + horizon)
This code snippet should just work, since align can accept a function type.
#set table(align: (x, y) => if y == 0 { center } else { left })
#table(
columns: (1fr, ) * 3,
[A], [A], [A],
[B], [B], [B]
)
By the way, changing figure.where(kind: table) to table should also work if you use raw table. Your posted rules are feasible if you use figure correctly:
#show figure.where(kind: table): it => {
show table.cell: set align(left + horizon)
show table.cell.where(y: 0): set align(center + horizon)
it
}
#figure(
table(
columns: (1fr, ) * 3,
[A], [A], [A],
[B], [B], [B]
),
caption: [Test]
)
1 Like
Yes, it did work! One thing to note:
set table(align: (x, y) => if y == 0 { center } else {left})
Should be written after set table(align: left + horizon). Im somewhat new to typst, so Idk how order of sets works, maybe my original code is correct, but my set table is just in wrong place.
P.S moved set table to the top, only Joseph’s solution works.