# read table from file , each row different number of columns

I have a data file where each row has a different number of columns, like this:

x   x   x   x
x   x   x
x   x   x   x   x   x
x   x
x   x   x   x   x
x   x   x
x   x   x   x
x   x   x   x
x   x   x   x   x


How can I read this into LaTeX and loop through the rows and columns appropriately? I will use the data (coordinates) to draw various numbers of rectangles with TikZ

I can't get it to work with \pgfplotstableread

(Note, I can get \pgfplotstableread to work with square matrices, but not "jagged matrices" as described above).

You could read it with latex, but simpler is just to edit it to normal tex syntax. If I save your example as d.txt then a commandline of

sed -e 's/\s\+/ \& /g'  -e 's/$/\\\\/' -e '1i\\\\begin{tabular}{*{20}{l}}' -e '$a\\\\end{tabular}' d.txt


Produces

\begin{tabular}{*{20}{l}}
x & x & x & x\\
x & x & x\\
x & x & x & x & x & x\\
x & x\\
x & x & x & x & x\\
x & x & x\\
x & x & x & x\\
x & x & x & x\\
x & x & x & x & x\\
\end{tabular}


Which you could either do before running latex or (using --shell-escape) on the fly during the latex run.

• I should have given more background - the table are coordinates that I intend to draw various rectangles with in TikZ. So actually I don't want to produce a table in LaTeX. – cmo Feb 26 '14 at 14:31
• @M.P. well same applies actually, whatever syntax would be convenient to read from tikz you could generate instead of the tabular, just by tweaking the sed. – David Carlisle Feb 26 '14 at 14:37