I don’t understand the logic behind additional id
and task
arguments that create 2 rows of 2 columns in a 3 column table. Is this intended? IMO, this is not readable and not how tables are usually used.
Also, not sure if you actually need to use dictionary over a list. From the for loop, it looks like you just want to create the table provided in the OP. And normally you would put table in a figure with a caption and maybe add a label.
If you really just want to recreate the table, use this:
#let exercise-table(result: ()) = table(
columns: (auto, 1fr, auto),
table.header[Name][Feedback][Status],
..result.map(dictionary.values).flatten(),
)
#exercise-table(
result: (
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
),
)
with id & task
#let exercise-table(id, task, result: ()) = table(
columns: (auto, 1fr, auto),
[ID],
table.cell(colspan: 2, id),
[Task],
table.cell(colspan: 2, task),
..result.map(dictionary.values).flatten(),
)
#exercise-table(
"1",
"Test",
result: (
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
),
)
Or this:
#let exercise-table(result) = table(
columns: (auto, 1fr, auto),
table.header[Name][Feedback][Status],
..result.map(dictionary.values).flatten(),
)
#exercise-table((
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
))
with id & task
#let exercise-table(id, task, result) = table(
columns: (auto, 1fr, auto),
[ID],
table.cell(colspan: 2, id),
[Task],
table.cell(colspan: 2, task),
..result.map(dictionary.values).flatten(),
)
#exercise-table(
"1",
"Test",
(
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
),
)
Or even this:
#let exercise-table(..result) = table(
columns: (auto, 1fr, auto),
table.header[Name][Feedback][Status],
..result.pos().map(dictionary.values).flatten(),
)
#exercise-table(
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
)
with id & task
#let exercise-table(id, task, ..result) = table(
columns: (auto, 1fr, auto),
[ID],
table.cell(colspan: 2, id),
[Task],
table.cell(colspan: 2, task),
..result.pos().map(dictionary.values).flatten(),
)
#exercise-table(
"1",
"Test",
(name: "John", feedback: "Did not find the button", status: "Not OK"),
(name: "Jane", feedback: "Did find the button immediately", status: "OK"),
)
But without additional context, I don’t see a point in using the dictionary:
// Row schema: (name, feedback, status)
#let exercise-table(..result) = table(
columns: (auto, 1fr, auto),
table.header[Name][Feedback][Status],
..result.pos().flatten(),
)
#exercise-table(
("John", "Did not find the button", "Not OK"),
("Jane", "Did find the button immediately", "OK"),
)
with id & task
// Row schema: (name, feedback, status)
#let exercise-table(id, task, ..result) = table(
columns: (auto, 1fr, auto),
[ID],
table.cell(colspan: 2, id),
[Task],
table.cell(colspan: 2, task),
..result.pos().flatten(),
)
#exercise-table(
"1",
"Test",
("John", "Did not find the button", "Not OK"),
("Jane", "Did find the button immediately", "OK"),
)
The cool thing about dictionaries though is that they preserve order:
You can iterate over the pairs in a dictionary using a for loop. This will iterate in the order the pairs were inserted / declared.
Which is why converting it to flatten array works.