Because I have multiple files with the same set of columnnames, which I want to show in one table, I tried to use to the \copycolumn macro (see thread in url) in combination with for each loops.
No error is produced but it does not add the specified columns. When I omit the foreach loops it does work. I assume the scope of the foreach loops messes up the variable that refers to the new table (\dataCombined in this case), i.e. \dataCombined is local in the foreach loops instead of global.
I have no idea how to fix this.
Code: Select all
\begin{filecontents}{testfile1.csv}
x,y,z
1,0.2,0.5
2,0.3,0.4
3,0.2,0.6
\end{filecontents}
\begin{filecontents}{testfile2.csv}
x,y,z
1,0.8,0.05
2,0.7,0.2
3,0.8,0.1
\end{filecontents}
\documentclass{article}
\usepackage{tikz, pgfplots, pgfplotstable,pgffor} %extract table from csv
\pgfplotsset{compat=1.10}
%% Macro made by hugovdberg in thread described above
%% Copy column takes 4 arguments: input table, input column, output table, output column
\newcommand{\copycolumn}[4]{
\pgfplotstablecreatecol[
col sep = comma, create col/copy column from table={#1}{#2}
]{#4}{#3}
}
\begin{document}
\pgfplotstablenew[]{3}{\dataCombined}
\copycolumn{filetest1.csv}{x}{\dataCombined}{x}d
\foreach \file in {testfile1,testfile2}{
\foreach \column in {y,z}{
\copycolumn{\file.csv}{x}{\dataCombined}{\file-\column}
}
}
\pgfplotstabletypeset [
col sep=comma,
string type,
]{\dataCombined}
\end{document}