2

I have the following table in a avg_value.csv file:

,M23,F23_1,M36,F44,F63,M70
M23,1.00,0.81,0.88,0.83,0.41,0.82
F23_1,,1.00,0.52,0.56,0.25,0.94
M36,,,1.00,0.62,0.94,0.96
F44,,,,1.00,0.43,0.23
F63,,,,,1.00,0.22
M70,,,,,,1.00

and I want to import it in my LaTeX file. Currently, I am using this code from http://pgfplots.sourceforge.net/gallery.html :

\usepackage{pgfplots}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepackage{array}
.
.
.
\pgfplotstabletypeset[
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule},
]
{pgfplotstable.avg_value.csv}

In fact, I do not import anything.

I receive as output message from kile:

! Package pgfplots Error: Could not read table file 'pgfplotstable.avg_value.csv'.


Changing the code as follows:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\usepackage{pgfplotstable}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{pgfplotstable}

\begin{document}

\begin{table}
\pgfplotstableread[col sep=comma]{pgfplotstable.avg_value.csv}\mytable
\pgfplotstabletypeset[
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column name={}}
]
{\mytable}
\caption[title.]{title.}
\label{tab:foo} 
\end{table}

\end{document}

did not solve the problem. Nothing really appears.

  • Try renaming the file to "test.csv" Is it working then? If so, try to avoid the dot after "stable" – Uwe Ziegenhagen Aug 23 '15 at 7:21
  • Changing the file into test.csv and the last line into {pgfplotstable.test.csv} does not solve the problem. – werty Aug 23 '15 at 7:29
7

You have to describe the structure of the csv file to pgfplotstable. And you have subscripts in your column/row names that you need to take care of. I've just removed them.

\documentclass{scrreprt}
\usepackage{pgfplotstable,booktabs}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% You don't need this part
% I did it to create your file 
\usepackage{filecontents} % <-- To create files on the fly

\begin{filecontents*}{avg_value.csv}
,M23,F231,M36,F44,F63,M70
M23,1.00,0.81,0.88,0.83,0.41,0.82
F231,,1.00,0.52,0.56,0.25,0.94
M36,,,1.00,0.62,0.94,0.96
F44,,,,1.00,0.43,0.23
F63,,,,,1.00,0.22
M70,,,,,,1.00
\end{filecontents*}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\pgfplotstabletypeset[
col sep = comma,
string replace*={_}{\textsubscript},
every head row/.style={before row=\toprule,after row=\midrule},
every last row/.style={after row=\bottomrule},
display columns/0/.style={string type,column name={}}
]
{avg_value.csv}

\end{document}

enter image description here

Please have a look at the manual for a quickstart if you need to get a feeling for common options.

  • This way does not import any .csv file. – werty Aug 23 '15 at 8:23
  • @werty Read my second paragraph – percusse Aug 23 '15 at 8:23
  • Do you mean writing \pgfplotstableread[col sep=comma]{avg_value.csv}\mytable ? – werty Aug 23 '15 at 8:27
  • 1
    @werty Yes exactly. Notice that underscore is a math active character in TeX in some cases it might cause problems so if you can, avoid it in file names and variables. – percusse Aug 23 '15 at 8:29
  • 1
    @DiaaAbidou \pgfplotstablegetelem can be used – percusse Dec 16 '16 at 22:08

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.