Hi, welcome to the forum!
A context expression is a single bit of content, which cannot be inspected anymore, the table gets this single bit of content and treats it as a single cell (See Why is the value I receive from context always content?). This means that if you need more than one cell out of the context expression you need to move your context further up, I’ve done that here by lifting it outside the table. Additionally looping over cells and just placing them next to each other will also just create a single long bit of content. The solution is to create an array of individual cells, which are then all applied as individual cells to table by the use of the spread operator ..
. Because the inner loop returned not one, but two cells, we flatten the inner arrays, otherwise we’d spread pairs of cells into the table, not cells itself.
#let title-headings() = context table(
// ..
..query(heading.where(level: 1))
.map(element => (
table.cell(text(size: 14pt, element.body)),
table.cell(text(size: 26pt, fill: white, "1")),
))
.flatten()
)