The layout order of grid
is row-major, i.e, for a sequence 0..5
you’d get:
#grid(columns: 3
[0], [1], [2],
[3], [4], [5],
)
As I understand it you’d like to display it in a column-major fashion for the same sequence:
#grid(columns: 3
[0], [2], [4],
[1], [3], [5],
)
To do this you need to transpose the sequence with respect to the number of columns, you can transpose an array by using zip
followed by flatten
:
#let questions2 = (
[2 x 1 =],
[2 x 2 =],
[2 x 3 =],
[2 x 4 =],
[2 x 5 =],
)
#let questions3 = (
[3 x 1 =],
[3 x 2 =],
[3 x 3 =],
[3 x 4 =],
[3 x 5 =],
)
#let questions4 = (
[4 x 1 =],
[4 x 2 =],
[4 x 3 =],
[4 x 4 =],
[4 x 5 =],
)
#let questions = array.zip(questions2, questions3, questions4).flatten()
#set align(center)
#grid(columns: (1fr, 1fr, 1fr), inset: 1em, ..questions)
You can see that we have exactly as many arrays as we have columns, we then zip them up such that we get a sequence of triplets, one from each sequence and then we concatenate these triplets back into one larger sequence, effectively transposing the array.
Resulting in the following output:
As an aside, your definitions can be automated too:
Summary
#let questions(n, k) = range(1, k + 1).map(i => [#n x #i =])
#let questions = array.zip(..range(2, 4).map(n => questions(n, 5))).flatten()
#set align(center)
#grid(columns: (1fr, 1fr, 1fr), inset: 1em, ..questions)