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?

2
  • 2
    Replace \begin{frame} with \begin{frame}[fragile].
    – nidhin
    Commented Sep 28, 2020 at 4:40
  • @nidhin Thank you! If you post that as an answer, I can accept it.
    – M47145
    Commented Sep 28, 2020 at 20:54

1 Answer 1

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}
3
  • 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
    Commented Sep 28, 2020 at 20:53
  • @M47145 Moving tikzstyle to the preamble works perfectly for me also, without fragile.
    – nidhin
    Commented Sep 28, 2020 at 22:00
  • Nevermind, I got it to work this way as well. Thank you! :)
    – M47145
    Commented Sep 29, 2020 at 13:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .