我试图在 Beamer 幻灯片上绘制 Tikz 图形,但收到以下错误:
! Package pgfplots Error: Could not read table file '" x y 0.8 0.8 1. 0.8 1. 1. 0.8 1. 0.9 0.8 1. 0.9 0.9 1. 0.8 0.9 0.9 0.9 "'. 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).
以下是产生此错误的 Beamer 演示文稿:
\documentclass[]{beamer}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{frame}
\begin{tikzpicture} \begin{axis}[view={40}{40},xmin=0,xmax=1,ymin=0,max=1,zmin=0,zmax=1]
\addplot3[patch,patch refines=0,mesh,black,patch type=biquadratic] table[z expr=x^2*y^2] {
x y
0.8 0.8
1. 0.8
1. 1.
0.8 1.
0.9 0.8
1. 0.9
0.9 1.
0.8 0.9
0.9 0.9
};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
我尝试了建议的解决方案但没有成功:
\documentclass[]{beamer}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{frame}
\begin{tikzpicture} \begin{axis}[view={40}{40},xmin=0,xmax=1,ymin=0,max=1,zmin=0,zmax=1]
\addplot3[patch,patch refines=0,mesh,black,patch type=biquadratic,row sep=crcr] table[z expr=x^2*y^2] {
x y\\
0.8 0.8\\
1. 0.8\\
1. 1.\\
0.8 1.\\
0.9 0.8\\
1. 0.9\\
0.9 1.\\
0.8 0.9\\
0.9 0.9\\
};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}
当我将其放入类文档tikzpicture
中时article
,代码按预期进行编译。有人知道 Beamer 中此错误的原因是什么吗?
答案1
将选项添加[fragile]
到frame
:
\begin{frame}[fragile]
答案2
可能,当 beamer 扫描frame
环境时,它会丢失行尾和表结构,因为内容在各种宏之间来回发送。最简单的方法是在框架外读取表并使用表名。但是,您也可以使用非平凡符号将列和行分隔开
\documentclass[]{beamer}
\usepackage{pgfplots}
\usepgfplotslibrary{patchplots}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\begin{axis}[view={40}{40},xmin=0,xmax=1,ymin=0,max=1,zmin=0,zmax=1]
\addplot3[patch,patch refines=0,mesh,black,patch type=biquadratic]
table[z expr=x^2*y^2,x=x,y=y,col sep=comma,row sep=crcr] {
x,y\\
0.8, 0.8 \\
1. , 0.8 \\
1. , 1. \\
0.8, 1. \\
0.9, 0.8 \\
1. , 0.9 \\
0.9, 1. \\
0.8, 0.9 \\
0.9, 0.9 \\
};
\end{axis}
\end{tikzpicture}
\end{frame}
\end{document}