I've already seen PGFplots and table with different number of elements in columns; but this is a slightly different question...

Consider the following MWE:


  col sep=comma,
% columns/0/.style={string type}, % nowork here; on typeset


\pgfplotstablegetrowsof{\mytable} %Determine no. of rows
\pgfmathtruncatemacro{\rows}{\pgfplotsretval} % pgfmathsetmacro float, this int

\typeout{Rows: \rows} % 3.0

Test 1: \\ \newline

\foreach \r in {0,1,...,\lastrow}{
  \pgfplotstablegetcolsof{\mytable} % how to get cols for this row???
  \noindent \r: \colzerotag\ - \numcolsstr \\

% just testing wide printout
  columns/0/.style={string type},


The data has variable number of columns; I would like to avoid re-parsing the data and padding with null columns. Using the data verbatim as is, pdflatex fails with:

% ! Package pgfplots Error: input table '' has an unbalanced number of columns in row '2' (expected '37' cols; got '34'). Maybe the input table is corrupted? If you need unbalanced data, consider using 'nan' in empty cells (perhaps combined with 'unbounded coords=jump').

If you keep on pressing "Enter", the document will eventually compile, and this is the output (click for full size):


(The full table is rendered, just to confirm whether pgfplotstable interprets the data per row as I do - that is, "start from beginning, and keep going for as many data columns are available"; and it seems that is the case. There is an empty column appended, apparently because of existence of trailing comma , in the data)

So, basically, what I'd like to do is loop through each row, print the first column label as identifier, then print the number of columns in that row; the expected output would be:

0: c002 - 37
1: c003 - 37
2: c004 - 34

Here just as a demo I use \pgfplotstablegetcolsof{\mytable} which will always use the first deduced number of columns for the table (so it always prints 37 regardless).

Is there a way I could achieve this only with pgfplotstable (possibly with an extra Latex package), without having to reparse the data?

  • This MWE is very confusing.... ~34 columns have nothing to do with the intrinsic problem.... Such excessive cell contents have nothing to do with the intrinsic problem.... Now you know the probably reasons, why you get not any answer since May. a) Could you break down your table to a few columns with simple entries? b) Could you make your MWE compilable? – cis Oct 27 '18 at 1:36

Your Answer

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

Browse other questions tagged or ask your own question.