Can a function passed as argument to a grid know about the number of rows?

Hello @junjios , this seems to be a duplicate of How can I format the last row of a table? - #6 by gezepi (tables and grids behave mostly the same way).

See the various solutions / workarounds.

Edit: This adapted from Discord works. But there are certainly cases where it will break. You can replace table with grid as needed.

#show table: it => {
  let cols = it.columns.len()
  let cells = it.children.len()

  let rows = calc.floor(
    cells / cols
      + calc.rem(
        cols - calc.rem(cells, cols),
        cols,
      ),
  )

  show table.cell.where(y: rows - 1): set text(blue)

  it
}

#table(
  columns: 2,
  ..for n in range(4) { (str(n),) }
)

1 Like