# tikz and beamer: shape rectangle split example from manual

The pgf manual has an example using the shape rectangle split on page 450 that is not working with the beamer class:

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{shapes.multipart}

\begin{document}

\begin{frame}{Testing}

\begin{tikzpicture}[my shape/.style={ rectangle split, rectangle split parts=#1, draw, anchor=center}]
\node [my shape=5] at (0,1) {
a\nodepart{two}b\nodepart{three}c\nodepart{four}d\nodepart{five}e};
\node [my shape=5, rectangle split horizontal] at (2,2) {
1\nodepart{two}2\nodepart{three}3\nodepart{four}4\nodepart{five}5};
\node [my shape=3] at (3,0.5) {
A\nodepart{two}B\nodepart{three}C};
\node [my shape=4, rectangle split horizontal] at (1.5,0.5) {
1\nodepart{two}2\nodepart{three}3\nodepart{four}4};
\end{tikzpicture}

\end{frame}

\end{document}


When this document is compiled with pdflatex, it gives the following error message:

! Illegal parameter number in definition of \test.
1
l.19   \end{tikzpicture}


Is this a known bug?

With the article class no error is found in the tikzpicture environment.

• I ran into this error message, and for me, the problem was simply a forgotten \end{frame}. – Lynn Nov 22 '16 at 20:21

The #1 seems to cause a problem. However, it can be fixed using the fragile option to the frame, which is described in the beamer manual, and causes the frame content to be differently handled.

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{frame}[fragile]{Testing}
\begin{tikzpicture}[my shape/.style={ rectangle split,
rectangle split parts=#1, draw, anchor=center}]
\node [my shape=5] at (0,1) {
a\nodepart{two}b\nodepart{three}c\nodepart{four}d\nodepart{five}e};
\node [my shape=5, rectangle split horizontal] at (2,2) {
1\nodepart{two}2\nodepart{three}3\nodepart{four}4\nodepart{five}5};
\node [my shape=3] at (3,0.5) {
A\nodepart{two}B\nodepart{three}C};
\node [my shape=4, rectangle split horizontal] at (1.5,0.5) {
1\nodepart{two}2\nodepart{three}3\nodepart{four}4};
\end{tikzpicture}
\end{frame}
\end{document}


• do you know how to solve this when doing a poster? I am using \documentclass[final]{beamer} \usepackage[scale=1.24]{beamerposter}  – elaRosca Jul 16 '14 at 18:04

You get this error if you try to use a parameter number, e.g., #1, inside the definition of a command which doesn't have an argument:

\documentclass{article}
\begin{document}
\def\test{\def\abc#1{#1}}
\end{document}


The solution is to double the parameter in this way:

\documentclass{article}
\begin{document}
\def\test{\def\abc##1{blub##1}}
\test \abc{cde}
\end{document}


In the case of beamer (or beamerposter package), doubling is not enough, as the content of a frame is stored twice: After doubling you get the same error but now for the command \beamer@doifinframe instead of \test.

So the solution is to redouble the parameter sign:

\documentclass{beamer}
\usepackage{tikz}
\begin{document}

\begin{frame}
\begin{tikzpicture}[
Node/.style = {rectangle, text width=####1}
]\tiny
\node[Node=5ex] {FFT};
\end{tikzpicture}
\end{frame}
\end{document}


I recommend this solution since in the beamerposter package there is not the possibility of using the traditional way of adding [fragile] to the frame.