#Auto insert table column for each column pair

4 messages · Page 1 of 1 (latest)

bleak bronze
#

I have a function for creating a pre-styled table. The table is given rows in the form of column pairs. For simplicity, lets say the table is defined like so:

#let MyTable(..cells) = table(columns:(center,center), ..cells)

And it would be used like:

#MyTable(
[11], [12],
[21], [22],
[31], [32],
)

Is there a way to a automatically insert a prefix column for each given column pair (thus making each row 3 columns)?
I would use this to auto insert row numbers (maybe other stuff too) into the table.

Internally, the table created would be something like this:

#table(
columns:(left, center, center),
[auto-col-1], [11], [12],
[auto-col-2], [21], [22],
[auto-col-3], [31], [32],
)
golden panther
#

Once you have the cells in an array, and there is no funky stuff to take care of (rowspan/colspan), then it's relatively easy to add extra things, like split the array into chunks, prepend a cell to each chunk, then .flatten() the array of arrays to an array again

#

array methods to use: .chunks(2) (each row of 2 cells becomes a chunk), .map() (prepend something to each row) .flatten() return to a flat array

#

Also .enumerate() to get hold of an index to use for map