If you put you cells in an array, you can automatically compute the number of rows according to the number of columns, like so:
#let n-cols = 3
#let cells = ([A], [B], [C], [D], [E], [F], [G])
#let n-rows = calc.ceil(cells.len() / n-cols)
#table(
columns: n-cols,
fill: (_, y) => if y == n-rows - 1 {
gray.lighten(50%)
} else {
none
},
..cells
)
If this is something you need in multiple places, you could even wrap it in a function, for example:
#let my-table(cells, ..args) = {
let columns = args.named().at("columns", default: 1)
let n-cols = if type(columns) == int {
columns
} else {
columns.len()
}
let n-rows = calc.ceil(cells.len() / n-cols)
table(
columns: columns,
..args,
fill: (_, y) => if y == n-rows - 1 {
gray.lighten(50%)
} else {
none
},
..cells
)
}