alexpovel / latex-cookbook

A comprehensive LaTeX template with examples for theses, books and more, employing the 'latest and greatest' (UTF8, glossaries, fonts, ...). The PDF artifact is built using CI/CD, with a Python testing framework.
MIT License
217 stars 20 forks source link

pgfplots error for tabular plot data from CSV #2

Closed alexpovel closed 2 years ago

alexpovel commented 2 years ago

Original issue (2021-10-18): https://collaborating.tuhh.de/alex/latex-cookbook/-/issues/9

A user ran into this error:

! Package pgfplots Error: Sorry, the requested column number '1' in table 'dat.
csv' does not exist!? Please verify you used the correct index 0 <= i < N..

It is similar to this error. How can this be fixed?

alexpovel commented 2 years ago

This can happen if you use pgfplotstable for plotting from tabular data, be it inline or from an outside file. If you use matlab2tikz, you might also run into the above error, since it potentially uses inline tables.

The culprit is this line:

https://github.com/alexpovel/latex-cookbook/blob/b847c85b0d4835a98889c0d2f948e32278b637fb/.devcontainer/image/acp.cls#L1388

This is a global default for all tables, assuming that they are comma-separated. The default is whitespace, which matlab2tikz uses, hence it breaks. You can override the column separator either in the above global option, or manually for each plot:

% See https://tex.stackexchange.com/a/251245/120853
\addplot3[surf] table [col sep=comma] {dat.csv};