3

I'm trying to add a very big graph in Beamer. However, it returns

Package tikz Error: Giving up on this path. Did you forget a semicolon?

Here is a small part of my code

 \documentclass{beamer}
    
    \usepackage{tikz}
    \usetikzlibrary{arrows}
    \tikzset{
      treenode/.style = {align=center, inner sep=0pt, text centered,
        font=\sffamily},
      arn_n/.style = {treenode, circle,black, draw=black, text width=1.3em}% 
    }
    
    \begin{document}
    \begin{frame}
    \frametitle{Paragraphs of Text}
    $\bf{Step \ 0 }$
    \begin{tikzpicture}[->,>=stealth',level distance = 2.5cm,
    level 1/.style={sibling distance=5.75cm},
    level 2/.style={sibling distance=1.95cm},
    level 3/.style={sibling distance=0.6cm}] 
    \node [arn_n] {}
        child{ node [arn_n] {} 
                child{ node [arn_n] {} 
                    child{ node [arn_n] {} } 
                                child{ node [arn_n] {}
                                }
                                child{ node [arn_n] {}
                                }
                }                           
        }
       
    \end{tikzpicture}
    \end{frame}

How to fix it?


update: I have add ; but it still returns error.

\begin{frame}
\frametitle{Paragraphs of Text}
\begin{tikzpicture}[->,>=stealth',level distance = 2.5cm,
level 1/.style={sibling distance=5.75cm},
level 2/.style={sibling distance=1.95cm},
level 3/.style={sibling distance=0.6cm}] 
\node [arn_n] {}
    child{ node [arn_n] {} ;
            child{ node [arn_n] {} 
                child{ node [arn_n] {} }; 
                            child{ node [arn_n] {}
                            };
                            child{ node [arn_n] {}
                            };
            };                            
    }; 
\end{tikzpicture}

\end{frame}

Missing $ inserted. $ l.137 \end{frame}

2
  • 6
    Add the missing semicolon after \node [arn_n] {} <all children>. Nov 22, 2013 at 4:38
  • The "Missing $" error is perhaps due to the underscore in arn_n?
    – JLDiaz
    Nov 22, 2013 at 9:33

2 Answers 2

5

Only one ; at the end is required. The errors come from the unpaired {} for each child. That is, every child must have a beginng { and an ending }. Also proper indentation would help in debugging. Actually, the use of underscore is not a problem here because it is a style name.

enter image description here

Here 3 cases are demonstrated because you have defined 3 levels.

Code

\documentclass{beamer}
    \usepackage{tikz}
    \usetikzlibrary{arrows}
    \tikzset{
      treenode/.style = {align=center, inner sep=0pt, text centered,
        font=\sffamily},
      arn_n/.style = {treenode, circle,black, draw=black, text width=1.3em},% 
    level distance = 2.5cm,
    level 1/.style={sibling distance=5.75cm},
    level 2/.style={sibling distance=1.95cm},
    level 3/.style={sibling distance=0.6cm}
}

    \begin{document}
    \begin{frame}
    \frametitle{Paragraphs of Text}
    $\bf{Step 0 }$\\
    \begin{tikzpicture}[scale=0.5] 
\node [arn_n] {0}
    child{ node [arn_n] {1} 
           child{node [arn_n] {2}} 
           child{node [arn_n] {2}}  
           child{node [arn_n] {2}}
           child{node [arn_n] {2}}};                             
 \end{tikzpicture}
\begin{tikzpicture}[scale=0.5]
\node [arn_n] {0}
    child{node [arn_n] {1}} 
    child{node [arn_n] {1} 
          child{node [arn_n] {2}}
          child{node [arn_n] {2}}
          child{node [arn_n] {2}}};    
\end{tikzpicture} 
\begin{tikzpicture}[scale=0.5]
\node [arn_n] {0}
    child{node [arn_n] {1}} 
    child{node [arn_n] {1} 
          child{node [arn_n] {2}}
          child{node [arn_n] {2}
                child{node [arn_n]{3}}}};    
\end{tikzpicture}                              
\end{frame}
\end{document}
2
  • Where exactly is the unpaired {} hiding? Taking the two provided MWE, just adding or removing semicolons seems to give the desired result (and I agree that proper indentation helps a lot!) Nov 22, 2013 at 18:21
  • Ok, in my first case, the first child has no }, meaning it has offsprings which is closed at the end. My second case, the first child is closed. This means s/he has sisters or brothers. Since your case have many semicolons and I have no way to kown what the tree is like, I gave 3 cases for you to know the tricks.
    – Jesse
    Nov 22, 2013 at 18:37
4

As for your updated example, I am afraid you inserted too many semicolons. You only need the last one after \node [arn_n] {} <all children>;

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{arrows}
\tikzset{
    treenode/.style = {align=center, inner sep=0pt, text centered,
        font=\sffamily},
    arn_n/.style = {treenode, circle,black, draw=black, text width=1.3em}% 
}

\begin{document}
    \begin{frame} 
        \frametitle{Paragraphs of Text}
        \begin{tikzpicture}[
            ->,
            >=stealth',
            level distance = 2.5cm,
            level 1/.style={sibling distance=5.75cm},
            level 2/.style={sibling distance=1.95cm},
            level 3/.style={sibling distance=0.6cm}
            ] 
            \node [arn_n] {}
            child{ 
                node [arn_n] {} 
                child{ node [arn_n] {} 
                    child{ node [arn_n] {} }
                    child{ node [arn_n] {} }
                    child{ node [arn_n] {} }
                }
            }; 
        \end{tikzpicture}
    \end{frame}
\end{document}

enter image description here

This answer was edited incorporating information from @Jesse's answer. So please accept his answer instead!

You must log in to answer this question.

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