#How to create tables sorted in a special order?
35 messages · Page 1 of 1 (latest)
Because tables are populated ltr then ttb, I think you have to transpose the rows into columns with array.zip(), like this:
?r ```
#let items = "ABCDEFGHIJKL".clusters()
#let columns = items.chunks(4)
#let rows = array.zip(..columns).join()
#table(columns: 3, ..rows)
A little closer to your table:
?r ```
#let items = (
"ABCDEFGHIJKLMNPQSTUZ".clusters()
.enumerate().map(((i, v)) => ([#(i + 1)], v))
)
#let columns = items.chunks(5)
#let rows = array.zip(..columns).flatten()
#table(columns: 8, align: (right, left)*4, ..rows)
that was what I was working towards, just with the steps broken out a little more
?r
#let pairs = (
("1", "Acker"), ("2", "Black"), ("3", "Cruz"), ("4", "Dallas"),
("5", "Engel"), ("6", "Fox"), ("7", "Gee"), ("8", "Haak"),
("9", "Iyer"), ("10", "Joshi"), ("11", "Kask"), ("12", "Lee"),
("13", "Moss"), ("14", "Nash"), ("15", "Park"))
#table(columns: 6,
align: (right, left)*3,
..array.zip(..pairs.chunks(5)).flatten()
)
if the numbers and names aren't already paired in whatever input format you've got them with, you just need another chunks
?r
#let pairs = (
"1", "Acker", "2", "Black", "3", "Cruz", "4", "Dallas",
"5", "Engel", "6", "Fox", "7", "Gee", "8", "Haak",
"9", "Iyer", "10", "Joshi", "11", "Kask", "12", "Lee",
"13", "Moss", "14", "Nash", "15", "Park"
)
#table(columns: 6,
align: (right, left)*3,
..array.zip(..pairs.chunks(2).chunks(5)).flatten()
)
None of these solutions preserve the selection order, which might lead to accessibility concerns.
I think there might be a hacky way to preserve the selection order with columns?
What do you mean? You mean the argument order?
That doesn't matter, since the internal layout algorithm will layout per row
I mean, if you select the text with mouse and copy it elsewhere, the copied content should be in the correct order.
I'm not sure that's possible with built-in tables
You'll have to roll out your own thing
Can tables be split into multiple columns with columns?
One way could be to have a stack of stacks :
#stack(dir: ltr, col1, col2, col3, ...)
where colN = stack(dir: ttb, ..cols.at(N - 1))
The columns parameter only specifies the amount of columns in the table
And their respective sizes
I mean something like columns(grid(...)).
?r #set page(height: 150pt) #columns(2, grid(columns: 2, ..(([a],) * 30).enumerate().join().map(x => [#x])))
Perhaps this?
Yes, this one.
Looks like I have to calculate the height of the table by myself...
?r
#let random-table(column-count: 2, ..items) = context {
let entries-enum = enum(
numbering: "1",
body-indent: 1em,
..items.pos()
)
block(
height: (measure(entries-enum).height + par.leading) / column-count - par.leading,
columns(column-count, gutter: 3pt, entries-enum)
)
}
#random-table(
column-count: 4,
"Acker", "Black", "Cruz", "Dallas", "Engel",
"Fox", "Gee", "Haak", "Iyer", "Joshi",
"Kask", "Lee", "Moss", "Nash", "Park",
"Qadir", "Singh", "Tran", "Ueda", "Zheng",
)