# \pgfplotstableread not working in Tex Live 2022?

EDIT I'm writing a thesis, and this is my first time using LaTeX. I've updated the code to hopefully help you compile this.

My charts used to work beautifully but after changing the Overleaf engine to Tex Live 2022, none of my charts will render. When I place the data inside the filecontents tag it compiles and the results are displayed, but when I put the data in a csv file it produces this error: "Package pgfplots Error: Sorry, could not retrieve column 'Year' from table 'Data/RCMCount'. Please check spelling or introduce name aliases.." I think the problem is with how Tex Live 2022 reads the file structure. The directory was previously always entered from the root folder where the thesis is compiled from. Is that no longer the case?

Thesis.tex: \include{Chapters/Chapter1.tex}

Chapter1.tex: \input{Figs/Quant/RCMCount.tex

RCMCount.tex: \pgfplotstableread[col sep=comma]{Data/RCMCount.csv}\datatable

The file structure is:

• Thesis.tex
• Chapters/
• Chapter1.tex
• Chapter2.tex
• Data/
• RCMCount.csv
• Figs/
• Qual/
• Quant/
• RCMCount.tex

The file contents of RCMCount.tex are provided in a manner that will hopefully allow you to compile. Note that the directory of the file contents is changed on account of the requested filecontents:

\documentclass{report}

\usepackage{tikz} % To generate the plot from csv
\usepackage{tikz-cd} % cumulative diagrams
\usetikzlibrary{shapes.geometric, arrows.meta}
\usetikzlibrary{positioning}
\usepackage{pgfplots} % To render plots and figures
\usepgfplotslibrary{colorbrewer} % To use pretty colour schemes
\usepackage{pgfplotstable} % To get CSV file into table
\usepackage{csvsimple}  % Use to Read/Write CSV files

\begin{filecontents}{RCMCount.csv}
Year,RoutineCognitive,NonRoutineCognitive,RoutineManual,NonRoutineManual,Sales
2012,87844,326396,61490,39726,50416
2013,114641,397172,84146,62090,70910
2014,157185,535345,131329,125587,98881
2015,162600,522584,119129,106838,107792
2016,165488,571951,148953,115297,108614
2017,178961,625967,192735,120444,112643
2018,159267,585545,167197,112728,91870
2019,166180,648406,160953,118405,99465
\end{filecontents}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=\linewidth, % Scale the plot to \linewidth
xlabel={Years},
ylabel={Count},
xtick=data, table/col sep=comma, xticklabels from table={\datatable}{Year},
xticklabel style={/pgf/number format/1000 sep=,rotate=60,anchor=east},
y unit=Thousands,
legend style={at={(0.5,-0.2)},anchor=north}, % Put the legend at the bottom
cycle list/Set1-5
]

\addplot+ table[col sep=comma, x=Year, y=RC] {\datatable};
\addplot+ table[col sep=comma, x=Year, y=NRC] {\datatable};
\addplot+ table[col sep=comma, x=Year, y=RM] {\datatable};
\addplot+ table[col sep=comma, x=Year, y=NRM] {\datatable};
\addplot+ table[col sep=comma, x=Year, y=S] {\datatable};
\end{axis}
\end{tikzpicture}

\end{document}


Have I done something wrong or has the directory system changed?

Below are screenshots of my results. Thank you so much for your help.

• Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Sep 16 at 14:38
• Also add part of RCMCount.csv inside \begin{filecontents} ... \end{filecontents}. As it is now, no one can test your code. Sep 16 at 14:42
• I've updated the code to include the contents you are asking for and provided some additional details about my file structures. This is my first time posting. Thanks for the help @hpekristiansen Sep 21 at 6:09

Note: The first part of this answer is based on the OP's original question that was changed later. See below for an update.

The main problem of the code you show is that you set col sep=comma at various places, but the file you show uses tabs and not commas to separate the columns. If I remove all occurences of col sep=comma, the code works just fine (tested with TeX Live 2022).

I removed packages that are unnecessary for this example and added a missing library that is needed to be able to use y unit=Thousands:

\documentclass{report}

\usepackage{pgfplots} % To render plots and figures
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{colorbrewer} % To use pretty colour schemes
\usepgfplotslibrary{units}

\begin{filecontents}{RCMCount.csv}
Year    RC      NRC     RM      NRM     S
2012    87844   326396  61490   39726   50416
2013    114641  397172  84146   62090   70910
2014    157185  535345  131329  125587  98881
2015    162600  522584  119129  106838  107792
2016    165488  571951  148953  115297  108614
2017    178961  625967  192735  120444  112643
2018    159267  585545  167197  112728  91870
2019    166180  648406  160953  118405  99465
\end{filecontents}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=\linewidth, % Scale the plot to \linewidth
xlabel={Years},
ylabel={Count},
xtick=data,
xticklabels from table={\datatable}{Year},
xticklabel style={
/pgf/number format/1000 sep=,
rotate=60,
anchor=east},
y unit=Thousands,
legend style={
at={(0.5,-0.2)},
anchor=north
}, % Put the legend at the bottom
cycle list/Set1-5
]

\end{axis}
\end{tikzpicture}

\end{document}


Edit

With the new CSV data the OP provided, it is of course necessary to add col sep=comma. However, it is sufficient to add this option once when the data in read using \pgfplotstableread.

Since the column names are different now, one needs to change the y values in each \addplot+ command, so that the values match the column names in the CSV file.

\documentclass{report}

\usepackage{pgfplots} % To render plots and figures
\pgfplotsset{compat=1.18}
\usepgfplotslibrary{colorbrewer} % To use pretty colour schemes
\usepgfplotslibrary{units}

\begin{filecontents}{RCMCount.csv}
Year,RoutineCognitive,NonRoutineCognitive,RoutineManual,NonRoutineManual,Sales
2012,87844,326396,61490,39726,50416
2013,114641,397172,84146,62090,70910
2014,157185,535345,131329,125587,98881
2015,162600,522584,119129,106838,107792
2016,165488,571951,148953,115297,108614
2017,178961,625967,192735,120444,112643
2018,159267,585545,167197,112728,91870
2019,166180,648406,160953,118405,99465
\end{filecontents}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
width=\linewidth, % Scale the plot to \linewidth
xlabel={Years},
ylabel={Count},
xtick=data,
xticklabels from table={\datatable}{Year},
xticklabel style={
/pgf/number format/1000 sep=,
rotate=60,
anchor=east},
y unit=Thousands,
legend style={
at={(0.5,-0.2)},
anchor=north
}, % Put the legend at the bottom
cycle list/Set1-5
]


• @Tearlin I updated my answer to make it fit your new code. It still works if I adjust the y values and add col sep=comma once (when \pgfplotstableread is used). Sep 21 at 6:24
• @Tearlin I see. Where do you store the file? It should be in the same directory as the .tex file. At least given the code you show. Do you maybe store it in another directory or in a subdirectory? Sep 21 at 10:16