Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to migrate my tables to pgfplotstables. I used to have a macro for the rows of my tables, partly, because Kile used to.

So currently, my tables more or less look like:

oldtable:
\begin{tabular}{ccc}
1&2&3\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
\end{tabular}

And I want to migrate that to something like:

newtable:
\pgfplotstabletypeset[debug]{
one & two & three\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
}

But that fails with the following error:

./main.tex:28: Package pgfplots Error: input table '<inline_table>' has an unba
lanced number of columns in row '1' (expected '3' cols; got '1'). Maybe the inp
ut table is corrupted? If you need unbalanced data, consider using 'nan' in emp
ty cells (perhaps combined with 'unbounded coords=jump').

------- PGFPLOTSTABLE DEBUG MODE: --------
./main.tex:28: Undefined control sequence.
\\  ->\let \reserved@e 
                       \relax \let \reserved@f \relax \@ifstar {\let \reserv...
l.28 }

I suppose that is because the macros don't get expanded. I don't necessarily want to edit all the tables. So my question is: How to make pgfplotstables read my table definition?

Full example:

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}

% global settings
\pgfplotstableset{
    col sep = &,
    row sep=\\,
    %string type, %% The error changes when enabling this type
}

\newcommand{\myrow}{foo & bar & baz\\}
\newcommand*{\rowentry}[6]{#1 & #2 & #3\\} %& #4}\\}
\begin{document}

oldtable:
\begin{tabular}{ccc}
1&2&3\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
\end{tabular}

newtable:
\pgfplotstabletypeset[debug]{
one & two & three\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
}

\end{document}
share|improve this question
add comment

1 Answer

up vote 5 down vote accepted

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}

% global settings
\pgfplotstableset{
    col sep = &,
    row sep=\\,
    string type, %% The error changes when enabling this type
}

\newcommand{\myrow}{foo & bar & baz\\}
\newcommand*{\rowentry}[6]{#1 & #2 & #3\\} %& #4}\\}

\def\foo#1[#2]#3{{
\let\\\relax
\gdef\tmpa{#1[#2]}%
\xdef\tmpb{\noexpand\tmpa{#3}}}%
\tmpb}

\begin{document}

oldtable:
\begin{tabular}{ccc}
1&2&3\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
\end{tabular}

\foo
\pgfplotstabletypeset[debug]{
one & two & three\\
\myrow{}
\rowentry{1}{2}{3}{4}{5}{6}
}

\end{document}
share|improve this answer
    
You, sir, are awesome. Thanks. It works with the small caveat of one having to provide the optional argument. But that's fine. It looks much like dark magic to me and I am afraid I would have been able to come up with that myself. Can you explain a little what it does, if it's not too much to ask for? –  Frederick Nord Mar 21 '13 at 15:57
    
It could be re-arranged to not requote the argument or you could have to functions \def\foob#1#2{{ \let\\\relax \gdef\tmpa{#1}% \xdef\tmpb{\noexpand\tmpa{#2}}}% \tmpb} to use in the no [] case. It simply uses \xdef to expand any macros in the main argument of \pgfplotstabletypeset before \pgfplotstabletypeset is called, so the pgf code never sees `myrow` or \rowentry, the string type that you had added but commented out is then needed as teh pgf code then does see foo & bar & baz which are not numbers:-) –  David Carlisle Mar 21 '13 at 16:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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