3

I'm trying to come up with a nice schematic of recursive calls using tikz, but the result is not what I expect as one label is flipped without a reason:

enter image description here

The MWE is:

\documentclass[xcolor=dvipsnames]{beamer}

\mode<presentation> {

\usetheme{default}
}


\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzstyle{node} = [rectangle, rounded corners, minimum width=2cm, minimum height=0.5cm,text centered, draw=black]
\tikzstyle{arrow} = [thick,->,>=stealth]

\addtobeamertemplate{block begin}{}{\justifying}  %new code

\usepackage{listings}

% Default fixed font does not support bold face
\DeclareFixedFont{\ttb}{T1}{txtt}{bx}{n}{12} % for bold
\DeclareFixedFont{\ttm}{T1}{txtt}{m}{n}{12}  % for normal

% Python style for highlighting
\newcommand\pythonstyle{\lstset{language=Python,
  basicstyle=\ttm\scriptsize,
  showstringspaces=false,
}}

% Python environment
\lstnewenvironment{python}[1][mathescape]
{
\pythonstyle
\lstset{#1}
}
{}

\begin{document}


\begin{frame}[fragile]

\begin{figure}
\begin{tikzpicture}[node distance=2cm, scale=0.8, every node/.style={scale=0.8}]

\node (fact3) [node] {
\begin{python}
fact(3):
    n = 3
    return 3*fact(2)
\end{python}
};
\node (fact2) [node, below of=fact3] {
\begin{python}
fact(2):
    n = 2
    return 2*fact(1)
\end{python}
};
\node (fact1) [node, below of=fact2] {
\begin{python}
fact(1):
    n = 1
    return 1*fact(0)
\end{python}
};
\node (fact0) [node, below of=fact1] {
\begin{python}
fact(0):
    n = 0
    return 1
\end{python}
};
 \path[->]                 (fact3)    edge[bend left=30]                node[swap]  {}       (fact2);
 \path[->]                 (fact2)    edge[bend left=30]                node[swap]  {}       (fact1);
 \path[->]                 (fact1)    edge[bend left=30]                node[swap]  {}       (fact0);
 \path[->, dashed]   (fact0)    edge[bend left=30]                node[pos=0.5, sloped, above]  {1}       (fact1);
 \path[->, dashed]   (fact1)    edge[bend left=30]                node[pos=0.5, sloped, above]  {1}       (fact2);
 \path[->, dashed]   (fact2)    edge[bend left=30]                node[pos=0.5, sloped, above]  {2}       (fact3);
\end{tikzpicture}
\caption{Recursive factorial calls}
\end{figure}

\end{frame}


\end{document} 
7
  • Your code is not compilable and so can't be tested. Commented Apr 8, 2015 at 15:15
  • I added the entire file that reproduces this error. It seems the figure environment may be the culprit?
    – aaragon
    Commented Apr 8, 2015 at 15:28
  • 3
    Neat, this lists (figure is a trivlist in beamer) really have some interesting side effect. You can avoid the flip by using \begin{figure}\leavevmode ... Commented Apr 8, 2015 at 15:39
  • As a desperate measure, you may add ... node[pos=0.5,sloped,rotate=180, above] {2}.... Aside, tikzstyle is deprecated, use positioning library and use below=of syntax.
    – user11232
    Commented Apr 8, 2015 at 15:40
  • How would you put those numbers vertical instead of horizontal?
    – aaragon
    Commented Apr 8, 2015 at 15:41

1 Answer 1

2

Neat, this lists (figure is a trivlist in beamer) really have some interesting side effect. You can avoid the flip by using \begin{figure}\leavevmode ...

You must log in to answer this question.

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