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

I need to plot data files which contain a comment in the last line, like this:

0  2  4
1  5  7
2  9  5  
3 11  15
4 10  15

Now, pgfplots seems to have a problem with that giving me an error message complaining about an unbalanced number of columns.

My question is: How do I tell pgfplots to ignore the last row of the data file? (I know about the skip first option of pgfplotstable. Maybe there is an equivalent for the last row that I just couldn't find in the manual.)



\usepackage{pgfplotstable} % For \pgfplotstableread


0  2  4
1  5  7
2  9  5  
3 11  15
4 10  15


\addplot [no markers, red] table [x=0, y=1] {\total}; \addlegendentry{$1$}
\addplot [no markers, blue] table [x=0, y=2] {\total}; \addlegendentry{$2$}

share|improve this question
up vote 13 down vote accepted

The simplest way of doing this is by adding additional line comment characters. For example:

\pgfplotstableread[comment chars={T}]{total.dos}\total

Will compile properly, i.e. "T" is now considered to start a comment line.

share|improve this answer
Nice. Is there also a solution for disallowed words, or a solution that allows you to exclude certain line numbers? – Marc van Dongen Jan 22 '12 at 18:21
Particular line numbers are not so simple (as far as I know), although there are other questions knocking around on TeX.sx to do with reading particular lines. The comment chars is supposed to be a comma separated list, so I tried comment chars={THIS} but LaTeX didn't like it. May be limited to single characters. – qubyte Jan 22 '12 at 18:27
Thank you. I didn't know about comment chars. – Philipp Jan 22 '12 at 18:51
You could also prefix the lines you want ignored with a common comment character, such as #. This is pretty easy to do in an editor and leaves letters, such as T, free to show up in the data. – Sharpie Jan 22 '12 at 20:12
@Sharpie: If this was an option, then Philipp could simply delete those lines. I'm assuming that Philipp needs a semi-automatic way to handle these files, which can't be altered directly. – qubyte Jan 23 '12 at 1:39

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.