3

I understand from this question that using macros within Beamer frames might create issues. Still I don't understand where should I place the macro definition for \pgfplotstabletypeset. Please consider the following MWE which generates ! Illegal parameter number in definition of \beamer@doifinframe. <to be read again>

\documentclass{beamer}

\usepackage{filecontents}

% For tables
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}
\usepackage{etoolbox}
\usepackage{units}

\pgfplotsset{compat=1.9}

\pgfplotstableset{
    %font={\small},
    empty cells with={--}, %  replace empty cells with ’--’
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule}
}

%Separate digits with comma (e.g. 1,000,000)
\usepackage[group-separator={,}]{siunitx}
\sisetup{
  detect-all,
  detect-inline-family=math,
  detect-inline-weight=math,
  detect-display-math=true}

\usepackage{amsmath}
\usepackage[osf,sc]{mathpazo}

\begin{filecontents}{testdata.csv}
city, theta, x, y
paris, 30.0,   0.0,    0.0
rome, 60.0,   1.9098, 5.8779
athens, 90.0,   6.9098, 9.5106
seattle, 120.0,  13.09,  9.5106
cairo, 150000,  18.09,  5.8779
jakarta, 180.0,  20.0,   0.0
\end{filecontents}

\pgfplotstableread[col sep=comma]{testdata.csv}{\testdata}

\begin{document}

\begin{frame}

\pgfplotstabletypeset[
  columns/city/.style={string type},
  columns/theta/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
  columns/x/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
  columns/y/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
 col sep=comma]{\testdata}

\end{frame}


\end{document}
6
  • 1
    Add the option [fragile] to the frame. Nov 30, 2013 at 11:06
  • @ClaudioFiandrino an answer?
    – cmhughes
    Nov 30, 2013 at 15:29
  • @cmhughes: we have somewhere a great answer (among others) explaining why the option is needed, but I cannot find it now. I think this can be closed as duplicate. Anybody agree? Nov 30, 2013 at 15:56
  • Adding [fragile] solved the problem.
    – Francesco
    Nov 30, 2013 at 21:01
  • @ClaudioFiandrino I couldn't find an answer for the specific problem (which is ##1, that absorbed as an argument becomes #1, making the code illegal). Perhaps an answer is better.
    – egreg
    Apr 5, 2014 at 22:09

1 Answer 1

3

Adding the option fragile to the frame allows a correct processing:

\documentclass{beamer}
\usepackage{lmodern}
\usepackage{filecontents}

% For tables
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{array}

\pgfplotsset{compat=1.9}

\pgfplotstableset{
    %font={\small},
    empty cells with={--}, %  replace empty cells with ’--’
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule}
}

%Separate digits with comma (e.g. 1,000,000)
\usepackage[group-separator={,}]{siunitx}
\sisetup{
  detect-all,
  detect-inline-family=math,
  detect-inline-weight=math,
  detect-display-math=true}

\usepackage{amsmath}
\usepackage[osf,sc]{mathpazo}

\begin{filecontents}{testdata.csv}
city, theta, x, y
paris, 30.0,   0.0,    0.0
rome, 60.0,   1.9098, 5.8779
athens, 90.0,   6.9098, 9.5106
seattle, 120.0,  13.09,  9.5106
cairo, 150000,  18.09,  5.8779
jakarta, 180.0,  20.0,   0.0
\end{filecontents}

\pgfplotstableread[col sep=comma]{testdata.csv}{\testdata}


\begin{document}

\begin{frame}[fragile]{Title}

\pgfplotstabletypeset[
  columns/city/.style={string type},
  columns/theta/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
  columns/x/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
  columns/y/.style={assign cell
  content/.code={\pgfkeyssetvalue{/pgfplots/table/@cell content}{\num{##1}}}},
 col sep=comma]{\testdata}

\end{frame}


\end{document}

The result:

enter image description here

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.