[Tex/LaTex] tikz matrix undefined control sequence

beamertikz-pgf

I would like to use tkiz matrix but any compilation within a tikz picture ends with error:

! Undefined control sequence.
<argument> \pgf@matrix@last@nextcell@options

I wonder if there is no bug, since even this test file with code taken from pgf doc is not compiled, with both lualatex and xelatex engines:

\documentclass[11pt]{beamer}           
\usepackage{polyglossia}
\usepackage{tikz}
\usetikzlibrary{matrix}

\setdefaultlanguage{english}


\title{}
\author{}
\date{}

\begin{document}
\maketitle


\begin{frame}
   \frametitle{test}

\begin{tikzpicture}
\draw[help lines] (0,0) grid (4,2);
\node [matrix,fill=red!20,draw=blue,very thick] (my matrix) at (2,1)
{
\draw (0,0) circle (4mm); & \node[rotate=10] {Hello};\\
\draw (0.2,0) circle (2mm); & \fill[red](0,0) circle (3mm); \\
};
\draw [very thick,->] (0,0) |- (my matrix.west);
\end{tikzpicture}
\end{frame}

\end{document}

I am using texlive 2014, updated it today (but compilation error was there before I updated) under Arch Linux.
Could someone check whether this problem is reproductible on texlive 2014 or tell me what's wrong if it is not a bug?

Escaping the ampersands does not really help, every nodes are written at the same place

Many thanks

EDIT: the trouble is connected with beamer. This document compiles without problem if I change documentclass to article (switching of course frame and frametitle). Where can this trouble come from?

Best Answer

When matrix is used in a frame environment, you need ampersand replacement just as you would when the matrix is in the argument to a command:

\documentclass[11pt]{beamer}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{frame}
\frametitle{test}

\begin{tikzpicture}[ampersand replacement=\&]
  \draw[help lines] (0,0) grid (4,2);
  \node [matrix,fill=red!20,draw=blue,very thick] (my matrix) at (2,1)
    {
     \draw (0,0) circle (4mm); \& \node[rotate=10] {Hello};\\
     \draw (0.2,0) circle (2mm); \& \fill[red](0,0) circle (3mm); \\
    };
  \draw [very thick,->] (0,0) |- (my matrix.west);
\end{tikzpicture}
\end{frame}

\end{document}

Alternatively, use the fragile option (slower, as it writes the frame code in a file and inputs it):

\documentclass[11pt]{beamer}
\usepackage{fontspec}
\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

\begin{frame}[fragile]
\frametitle{test}

\begin{tikzpicture}
  \draw[help lines] (0,0) grid (4,2);
  \node [matrix,fill=red!20,draw=blue,very thick] (my matrix) at (2,1)
    {
     \draw (0,0) circle (4mm); & \node[rotate=10] {Hello};\\
     \draw (0.2,0) circle (2mm); & \fill[red](0,0) circle (3mm); \\
    };
  \draw [very thick,->] (0,0) |- (my matrix.west);
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here