TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
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. – Marco Daniel Aug 23 '12 at 18:49
No, the data comes in as a string, thats the problem.... – Twerp Aug 23 '12 at 19:46
Counting the elements of a string is really simple. Please provide a minimal example. The elements are separated by comma? – Marco Daniel Aug 24 '12 at 5:51
up vote 3 down vote accepted

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

share|improve this answer
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 '12 at 9:55
figured it out, thank you! – Twerp Aug 24 '12 at 13:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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