4

I am trying to plot a Tikz figure on a Beamer slide but receive the following error:

! 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).

Here is the Beamer presentation that generated this error:

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

I tried the suggested solution to no avail:

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

When I put the same tikzpicture into an article class document, the code compiles as expected. Does anybody know what is the cause of this error in Beamer?

Ubiquitous
  • 2,566

2 Answers2

10

Add the [fragile] option to the frame:

\begin{frame}[fragile]
Bibi
  • 1,532
3

Probably, when beamer is scanning the frame environment, it's loosing the line ends and the table structure because the contents are sent back and forth between various macros. The easiest is to read the table outside the frame and use the table name. But alternatively, you can make the column and rows separated with a nontrivial symbol

\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}
percusse
  • 157,807
  • Splendid, this solved my problem, after hours of back-and-forth with chatGPT :). However, It worked with just row sep=crcr, col sep didn't worked... – MPA95 Dec 05 '23 at 20:30