Assume I have a table with a dynamic number of rows and columns, and I want to fill the table with n elements. Assume an element has the constant length x, and I want to say make floor(linewitdth/x) columns per row so that the maximal number of elements is in a row. How would I write that in LaTeX?

  • LaTeX tables don't have a dynamical number of columns. The elements of the table are saved in a csv file? I think the package datatool will be the best choice. Aug 23, 2012 at 18:49
  • No, the data comes in as a string, thats the problem....
    – Twerp
    Aug 23, 2012 at 19:46
  • Counting the elements of a string is really simple. Please provide a minimal example. The elements are separated by comma? Aug 24, 2012 at 5:51

1 Answer 1


If your elements all have the same width x (either naturally or because you put each one in a \makebox[3cm][l]{.....} ) then you don't need a table construct or to do any arithmetic, just place them one after another in a flushleft environment and the paragraph breaker will naturally fit as many as it can on each line, and vertical alignment is automatic.

See this technique being used

building a table of images


enumerate in multicols

  • ok, this looks promisingg, last stupid question - for a given string x, how do i determine the width and put it in your formula?
    – Twerp
    Aug 24, 2012 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.