如何在 Beamer 框架中插入表格

如何在 Beamer 框架中插入表格

我理解这个问题在框架中使用宏Beamer可能会产生问题。我仍然不明白应该将宏定义放在哪里\pgfplotstabletypeset。请考虑以下 MWE,它会产生! 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}

答案1

将选项添加fragile到框架可以实现正确的处理:

\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}

结果:

在此处输入图片描述

相关内容