I created a dynamic table in order to cast inline CSV data easily to a table and want to use it now as a custom command, in order to make the table command easy to use for my colleagues.
This first table will generate the table I'd like to have:
\documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[table]{xcolor} \usepackage{pgfplotstable}\pgfplotsset{compat=newest} \usepackage{float} \begin{document} \begin{table}[H] \begin{center} \pgfplotstabletypeset[ col sep = comma, string type, string replace*={_}{\_}, every head row/.style={before row=\rowcolor{blue}\hline,after row=\hline}, every last row/.style={after row=\hline}, display columns/0/.style={string type,column type = {|l}}, every last column/.style={string type,column type = {l|}}, every head row/.append style={ before row={\rowcolor{blue}}, typeset cell/.code={ \ifnum\pgfplotstablecol=\pgfplotstablecols \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}\\}% \else \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}&}% \fi } } ]{ a,b,c,d aa,bb,cc,dd } \end{center} \caption{yay} \label{yayy} \end{table} \end{document} This does work and I have no issues. But it's huge and I'd like to wrap it in the following command:
\documentclass{article} \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage[table]{xcolor} \usepackage{pgfplotstable}\pgfplotsset{compat=newest} \usepackage{float} \newcommand{\csvtable}[2]{% \begin{table}[H] \begin{center} \pgfplotstabletypeset[ col sep = comma, string type, string replace*={_}{\_}, every head row/.style={before row=\rowcolor{blue}\hline,after row=\hline}, every last row/.style={after row=\hline}, display columns/0/.style={string type,column type = {|l}}, every last column/.style={string type,column type = {l|}}, every head row/.append style={ before row={\rowcolor{blue}}, typeset cell/.code={ \ifnum\pgfplotstablecol=\pgfplotstablecols \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}\\}% \else \pgfkeyssetvalue{/pgfplots/table/@cell content}{\textcolor{white}{##1}&}% \fi } } ]{% #2 }% \end{center} \caption{#1} \label{#1} \end{table} } \begin{document} \csvtable{my caption}{ this, is, csv, data a, b, c, d } \end{document} Now I get this error message, which does not help me, because I tried all those separator commands:
results.tex, line 69 Package pgfplots Error: Could not read table file '" this, is, csv, data a, b, c, d "' in 'search path=.'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\\' (refer to the pgfplotstable manual for details). Long story short. How may I embed the csv data correctly? I know there is also a method with \begin{custom} \end{custom} but I never worked with it and newcommand worked fine for me up to now.
Help appreciated!
Edit: Updated the sample with Rmanos suggestion.
