#How to create tables sorted in a special order?

35 messages · Page 1 of 1 (latest)

prime totem
#

This is a random table I want to typeset in Typst. You can see the content order by the selection. What is the simplest possible way to recreate this in Typst?

lime coral
#

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)

lime coral
#

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)

sick crescent
#

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()
)
sick crescent
#

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()
)
prime totem
#

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?

silk phoenix
#

That doesn't matter, since the internal layout algorithm will layout per row

prime totem
#

I mean, if you select the text with mouse and copy it elsewhere, the copied content should be in the correct order.

silk phoenix
#

I'm not sure that's possible with built-in tables

#

You'll have to roll out your own thing

prime totem
#

Can tables be split into multiple columns with columns?

silk phoenix
silk phoenix
#

And their respective sizes

prime totem
#

I mean something like columns(grid(...)).

silk phoenix
#

Ah, no

#

I mean unless you have a single column

#

In the grid

#

Then it could work

silk phoenix
silk phoenix
#

Perhaps this?

prime totem
#

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",
)