1

I'm attempting to do exactly the same thing as this question, namely adding edges between scopes. However, I'm working on a Beamer presentation using the \documentclass{beamer}, and the exact same code as the answers given there don't work. They work just fine when I use the article class. For example, I can't compile the following:

\documentclass{beamer}
\usepackage{tikz}

\begin{document} \begin{frame} \tikzstyle{vertex}=[circle,draw,fill=black!20]

\makeatletter \tikzset{% prefix node name/.code={% \tikzset{% name/.code={\edef\tikz@fig@name{#1 ##1}} }% }% } \makeatother

\begin{tikzpicture}

% ---- Copy 1 \begin{scope}[yshift=-32pt,prefix node name=G1] \node[vertex] (u) at (0, 0) {u}; \node[vertex] (v) at (0, 0) {v}; \end{scope}

% ---- Copy 2 \begin{scope}[yshift=32pt,prefix node name=G2] \node[vertex] (u) at (0, 0) {u}; \node[vertex] (v) at (0, 0) {v}; \end{scope}

\draw (G1 u) -- (G2 v);

\end{tikzpicture} \end{frame} \end{document}

I get the following error "! Package pgf Error: No shape named `G1' is known." and also "! Illegal parameter number in definition of \iterate."

Does anyone know of a workaround that works in Beamer?

M47145
  • 113

1 Answers1

2

Move the style definition to the preamble.

Also, \tikzstyle is considered deprecated, so I'd specify the vertex style in the \tikzset as well.

\documentclass{beamer}
\usepackage{tikz}
\makeatletter
\tikzset{%
  vertex/.style={circle,draw,fill=black!20},
  prefix node name/.code={%
    \tikzset{%
      name/.code={\edef\tikz@fig@name{#1 ##1}}
    }%
  }%
}
\makeatother
\begin{document}
\begin{frame}
\begin{tikzpicture}

% ---- Copy 1 \begin{scope}[yshift=-32pt,prefix node name=G1] \node[vertex] (u) at (0, 0) {u}; \node[vertex] (v) at (0, 0) {v}; \end{scope}

% ---- Copy 2 \begin{scope}[yshift=32pt,prefix node name=G2] \node[vertex] (u) at (0, 0) {u}; \node[vertex] (v) at (0, 0) {v}; \end{scope}

\draw (G1 u) -- (G2 v);

\end{tikzpicture} \end{frame} \end{document}

Torbjørn T.
  • 206,688
  • Thanks! This didn't fully fix the issue for me though. As suggested by user nidhin replacing \begin{frame} with \begin{frame}[fragile] fixed the issue. – M47145 Sep 28 '20 at 20:53
  • @M47145 Moving tikzstyle to the preamble works perfectly for me also, without fragile. – nidhin Sep 28 '20 at 22:00
  • Nevermind, I got it to work this way as well. Thank you! :) – M47145 Sep 29 '20 at 13:54