3

I have the following MWE (sorry for a long preamble, no longer know which are essential, taken from a larger document)

    \PassOptionsToPackage{table}{xcolor}
\documentclass[xcolor=dvipsnames]{beamer}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage{relsize}
%\tikzset{fontscale/.style = {font=\relsize{#1}}}
\usepackage{tikzscale}
\usetikzlibrary{backgrounds,shadings,shadows,shapes,chains,calc,positioning,decorations.pathreplacing}
\usetikzlibrary{shapes,chains,calc,positioning,decorations.pathreplacing}
\usetikzlibrary{arrows.meta}
\usepackage{comment}
\usepackage{tcolorbox}
%\captionsetup[figure]{labelfont={bf},name={Fig.},labelsep=period}
\usetikzlibrary{calc,arrows,decorations.pathmorphing,intersections}
\usetikzlibrary{patterns}
\usetikzlibrary{matrix,calc,shapes}
\tikzset{
  trnode/.style = {shape=circle, 
                     draw, anchor=center,
                     text width=1em, align=center,
                     inner sep=1ex},
  treenode/.style = {shape=rectangle, rounded corners,
                     draw, anchor=center,
                     text width=8em, align=center,
                     top color=sidewalk, bottom color=goldenAfternoon,
                     inner sep=1ex},
  mynode/.style = {shape=rectangle, rounded corners,
                     draw, anchor=center,
                     text width=2em, align=left,
                     top color=sidewalk, bottom color=goldenAfternoon,
                     },
  decision/.style = {treenode, diamond, inner sep=0pt},
  root/.style     = {treenode, font=\Large, bottom color=burgundy},
  env/.style      = {treenode, font=\ttfamily\normalsize},
  finish/.style   = {mynode, bottom color=burgundy},
  dummy/.style    = {circle,draw},
  whiteNode/.style= {trnode, top color = white, bottom color = white},
  blackNode/.style= {trnode, draw,pattern = north west lines, pattern color=goldenAfternoon}
}

\definecolor{burgundy}{HTML}{882426}
\definecolor{sidewalk}{HTML}{CDBEA7}
\definecolor{cinder}{HTML}{323030}
\definecolor{goldenAfternoon}{HTML}{C29545}

\tikzset{onslide/.code args={<#1>#2}{%
          \only<#1>{\pgfkeysalso{#2}}
          }}
\tikzstyle{highlight}=[burgundy,ultra thick]
\edef\sizetape{0.7cm}

\begin{document}
    \begin{frame}{Frame 1}
        \begin{figure}
            %\begin{tikzpicture}[remember picture,overlay,level/.style={sibling distance=60mm/#1}]
            \begin{tikzpicture}[level/.style={sibling distance=60mm/####1}]
                    \tikzstyle{tmtape}=[decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt},draw,minimum size={\sizetape},thick]
                    \tikzstyle{tmtap}=[draw,minimum size={\sizetape},black!50]
                \begin{scope}
                        \node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v0){\texttt{1}}
                        child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v1) {\texttt{2}} 
                            child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v3) {\texttt{3}}
                                child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v9) {\scriptsize{\texttt{4}}}}
                                child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v8) {\texttt{5}}}
                            }
                            child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v4) {\scriptsize{\texttt{6}}}}
                          }
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v2) {\texttt{7}}
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v5) {\scriptsize{\texttt{8}}}
                                child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v7) {\scriptsize{\texttt{9}}}}}
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v6) {\texttt{10}}}
                        };
                    \path[draw,very thick] (v0) -- (v1);
                    \path[draw,very thick] (v1) -- (v3);
                    \path[draw,very thick,color=burgundy] (v3) -- (v8);
                    %\path[draw,very thick] (v2) -- (v5);
                    %\path[draw,very thick] (v5) -- (v7);
                    %\path[draw,very thick] (v3) -- (v9);
                    \path[draw,very thick,color=burgundy] (v2) -- (v6);
                    \path[draw,very thick,color=burgundy] (v2) -- (v0);
                    %\path[draw,very thick] (v1) -- (v4);
                    \node[xshift=0.2cm,yshift=0.2cm] (w0) at (v0.north east) {\textit{-1}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w8) at (v8.north east) {\textit{3}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w3) at (v3.east) {\textit{9}};
                    \node[xshift=-0.2cm,yshift=0.2cm] (w1) at (v1.west) {\textit{-17}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w2) at (v2.north east) {\textit{13}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w6) at (v6.north east) {\textit{-2}};
                \end{scope}
                \begin{scope}[shift={($(v1.south)+(1,-4.5)$)},start chain=1 going right, node distance = 3.55mm]
                        \node [on chain=1,tmtape] (am17) {\texttt{-17}};
                        \node [on chain=1,tmtape] (am2) {\texttt{-2}};
                        \node [on chain=1,tmtape] (am1) {\texttt{-1}};
                        \node [on chain=1,tmtape] (a3) {\texttt{3}};
                        \node [on chain=1,tmtape] (a9) {\texttt{9}};
                        \node [on chain=1,tmtape] (a13) {\texttt{13}};
                        \coordinate (X) at ($(a13.south east)+(1,-1)$);
                        %\draw [decorate, decoration={brace,amplitude=10pt,mirror,raise=4pt},very thick,yshift=-2cm] (a8l.south  west) -- (a6f.south east) 
                    %   node[midway,yshift=-0.85cm] (hp0) {\footnotesize{\texttt{8-to-6 path}}};
                    %\draw [decorate, decoration={brace,amplitude=10pt,raise=4pt},very thick,yshift=-2cm] (a5f.north west) -- (a5l.north east) 
                    %   node[midway,yshift=0.85cm] (hp1) {\footnotesize{\texttt{omitted vertices}}};
                        \path [draw,dotted,thick,->,out=0,in=-45] (w8) -- ($(a3.north west)+(-0.07,0.07)$);
                        \draw [dotted,thick,->,bend right=90,in=-90,out=0] (w6.south) ..controls (X) .. ($(am2.south east)+(0.07,-0.07)$);
                \end{scope}
            \end{tikzpicture}
            %\caption{Path median query example.}
            %\label{fig02}
        \end{figure}
    \end{frame}
\end{document}

Essentially, I would like to highlight certain edges in the next slide, and am using an answer provided elsewhere in TeX.SO, but the problem is really in the scope feature of TikZ: I get the following error when run with pdflatex... Is there some incompatibility of scopes with Beamer?

  • 2
    off-topic: (i) first you make some order in your preamble (remove all twice loaded packages in libraries, group packages regarding their puprose) ; (ii) for mwe, which will show your problem, reduce preamble to minimum, which is necessary for your mwe; (iii) so far i haven't any problem to use scope in beamer. – Zarko May 7 '18 at 18:07
  • Possible duplicate: tex.stackexchange.com/q/119309/14500 – Paul Gaborit May 7 '18 at 20:58
  • 1
    @Ilonpilaaja Don't include your own answer in your MWE! – Paul Gaborit May 7 '18 at 21:04
2

If you use fragile content in a frame, such as your tikz picture, pass the fragile option to the frame:

\documentclass{beamer}
\usepackage{tikz}

\usetikzlibrary{chains}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathmorphing}

\definecolor{burgundy}{HTML}{882426}

\tikzset{onslide/.code args={<#1>#2}{%
          \only<#1>{\pgfkeysalso{#2}}
          }}
\tikzstyle{highlight}=[burgundy,ultra thick]

\begin{document}

    \begin{frame}[fragile]{Frame 1}
        \begin{figure}
            %\begin{tikzpicture}[remember picture,overlay,level/.style={sibling distance=60mm/#1}]
            \begin{tikzpicture}[level/.style={sibling distance=60mm/#1}]
                \edef\sizetape{0.7cm}
                \tikzstyle{tmtape}=[decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt},draw,minimum size=\sizetape,thick]
                \tikzstyle{tmtap}=[draw,minimum size=\sizetape,black!50]
                \begin{scope}
                        \node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v0){\texttt{1}}
                        child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v1) {\texttt{2}} 
                            child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v3) {\texttt{3}}
                                child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v9) {\scriptsize{\texttt{4}}}}
                                child {node [circle, decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v8) {\texttt{5}}}
                            }
                            child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v4) {\scriptsize{\texttt{6}}}}
                          }
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v2) {\texttt{7}}
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v5) {\scriptsize{\texttt{8}}}
                                child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw] (v7) {\scriptsize{\texttt{9}}}}}
                        child {node [circle,decorate, decoration={random steps,segment length=0.8pt,amplitude=0.2pt}, draw,very thick,color=burgundy] (v6) {\texttt{10}}}
                        };
                    \path[draw,very thick,onslide={<2>{highlight}}] (v0) -- (v1);
                    \path[draw,very thick,onslide={<2>{highlight}}] (v1) -- (v3);
                    \path[draw,very thick,color=burgundy] (v3) -- (v8);
                    %\path[draw,very thick] (v2) -- (v5);
                    %\path[draw,very thick] (v5) -- (v7);
                    %\path[draw,very thick] (v3) -- (v9);
                    \path[draw,very thick,color=burgundy] (v2) -- (v6);
                    \path[draw,very thick,color=burgundy] (v2) -- (v0);
                    %\path[draw,very thick] (v1) -- (v4);
                    \node[xshift=0.2cm,yshift=0.2cm] (w0) at (v0.north east) {\textit{-1}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w8) at (v8.north east) {\textit{3}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w3) at (v3.east) {\textit{9}};
                    \node[xshift=-0.2cm,yshift=0.2cm] (w1) at (v1.west) {\textit{-17}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w2) at (v2.north east) {\textit{13}};
                    \node[xshift=0.2cm,yshift=0.2cm] (w6) at (v6.north east) {\textit{-2}};
                \end{scope}
                %\begin{comment}
                \begin{scope}[shift={($(v1.south)+(1,-4.5)$)},start chain=1 going right, node distance = 3.55mm]
                        \node [on chain=1,tmtape] (am17) {\texttt{-17}};
                        \node [on chain=1,tmtape] (am2) {\texttt{-2}};
                        \node [on chain=1,tmtape] (am1) {\texttt{-1}};
                        \node [on chain=1,tmtape] (a3) {\texttt{3}};
                        \node [on chain=1,tmtape] (a9) {\texttt{9}};
                        \node [on chain=1,tmtape] (a13) {\texttt{13}};
                        \coordinate (X) at ($(a13.south east)+(1,-1)$);
                        %\draw [decorate, decoration={brace,amplitude=10pt,mirror,raise=4pt},very thick,yshift=-2cm] (a8l.south  west) -- (a6f.south east) 
                    %   node[midway,yshift=-0.85cm] (hp0) {\footnotesize{\texttt{8-to-6 path}}};
                    %\draw [decorate, decoration={brace,amplitude=10pt,raise=4pt},very thick,yshift=-2cm] (a5f.north west) -- (a5l.north east) 
                    %   node[midway,yshift=0.85cm] (hp1) {\footnotesize{\texttt{omitted vertices}}};
                        \path [draw,dotted,thick,->,out=0,in=-45] (w8) -- ($(a3.north west)+(-0.07,0.07)$);
                        \draw [dotted,thick,->,bend right=90,in=-90,out=0] (w6.south) ..controls (X) .. ($(am2.south east)+(0.07,-0.07)$);
                \end{scope}
                %\end{comment}
            \end{tikzpicture}
            %\caption{Path median query example.}
            %\label{fig02}
        \end{figure}
    \end{frame}
\end{document}
1

I found the solution here: https://groups.google.com/forum/#!topic/comp.text.tex/ox8dEYWg494 The fix is level/.style={sibling distance=60mm/#1 needs to be changed to level/.style={sibling distance=60mm/####1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.