Beginner help with number of columns of csv table

Hello,

New Typst user here who has never got very far writing code before…

I have created a 6 row 6 column table and imported it and displayed it with the below:

#let results = csv("typst-test.csv")

#table(
  columns: 6,
  ..results.flatten(),
)

Which works, but what could I replace “6” with so that I don’t need to hardcode in the number of columns and can let Typst work it out automatically?

What code is needed to count the number of columns?

Thank you!

Duncan

Hi, welcome to the forum!

Would this work? It means the length of the first row.

  columns: results.first().len(),

It does thank you!

1 Like

Hi @Duncan , welcome to the forum!

Now that @Y.D.X has provided an answer, please mark their post as the answer to this question. This distinguishes this question as answered but that post then is shown directly beneath your original post where the question is asked.

Speaking of asking a question, in How to post in the Questions category it mentions:

The title of your question should make clear what your post is about. Good titles are questions you would ask your friend about Typst.

Also, it’s great you posted code but it is even better if it is formatted. There is a section in the link above about this. The short version is you should use triple back ticks ```.
I’d also like to point out that since we don’t have a typst-test.csv file, the code you posted can’t be used directly. This didn’t slow down answering this specific question, but it can make a huge difference so keep it in mind. If you’re interested in this topic here’s a nice introduction: https://www.sscce.org/.

1 Like