#How to use enum numbering in table

10 messages · Page 1 of 1 (latest)

hidden valley
#

Hi, I have a usecase where I need to number the rows in the table and I was thinking of using enums for it. But how to use it?
#set enum(numbering: "1.")
#align(alignment.center + alignment.horizon)[#table(
   columns: (0.05fr, 0.5fr, 0.5fr),
[Here I want auto numbering],[Column1],[Column3]
)
]

lofty hemlock
#

?r ```ansi
#let numbered-table(columns: auto, ..args) = {
let columns-count = if type(columns) == int {
columns
} else if type(columns) == array {
columns.len()
} else {
1
}
let chunks(array, n) = {
range(array.len(), step: n)
.map(i => array.slice(i, calc.min(array.len(), i + n)))
}
table(
columns: columns-count + 1,
..args.named(),
..chunks(args.pos(), columns-count)
.enumerate()
.map(((n, chunk)) => (str(n + 1), ..chunk))
.flatten()
)
}

#numbered-table(
columns: 3,
[A], [B], [C],
[D], [E], [F],
[G], [H], [I],
)

smoky barn
#

Oh no, you're ||father|| faster

#

I think you can hack it with something like

#

?r

#let cells = (
  [Here I want auto numbering], [Column1], [Column3],
  [More lines], [Column2], [Column3]
)
#let numb = numbering.with("1.")
#for i in range(cells.len(), step: 3) {
  cells.at(i) = [#numb(int(i / 3)) #cells.at(i)]
}
#align(alignment.center + alignment.horizon)[#table(
     columns: (0.5fr, 0.5fr, 0.5fr),
     ..cells
   )
]
lofty hemlock
#

?r ```ansi
#let numbered-table(header-numbering: true, columns: auto, ..args) = {
let columns-count = if type(columns) == int {
columns
} else if type(columns) == array {
columns.len()
} else {
1
}
let chunks(array, n) = {
range(array.len(), step: n)
.map(i => array.slice(i, calc.min(array.len(), i + n)))
}
table(
columns: columns-count + 1,
..args.named(),
..chunks(args.pos(), columns-count)
.enumerate()
.map(((n, chunk)) => {
if n == 0 and not header-numbering {
([N], ..chunk)
} else {
if header-numbering {
n += 1
}
(str(n), ..chunk)
}
})
.flatten()
)
}

#numbered-table(
header-numbering: false,
columns: 3,
[A], [B], [C],
[D], [E], [F],
[G], [H], [I],
)

lofty hemlock
#

here with configurable header numbering