This is view of the original algorithm:
Aside from duplicating the algorithm (with heading and content), since your were particularly interested in the numbering, the following does something similar using PGF/TikZ
and algorithmicx
. Moreover, I've used the following two answers to obtain the desired result:
\documentclass{article}
\usepackage{algpseudocode}
\usepackage{tikz}
% https://tex.stackexchange.com/questions/7032/good-way-to-make-textcircled-numbers/7045#7045
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
\node[shape=circle,draw,inner sep=1pt] (char) {#1};}}
\begin{document}
% https://tex.stackexchange.com/questions/25019/how-to-place-a-program-and-a-text-side-by-side/25026#25026
\algrenewcommand{\alglinenumber}[1]{\scriptsize\circled{#1}}% circled line numbers
\begin{algorithmic}[1]% Taken from the algorithmicx package documentation
\Procedure{Euclid}{$a,b$}
\State $r\gets a\bmod b$
\While{$r\not=0$}
\State $a\gets b$
\State $b\gets r$
\State $r\gets a\bmod b$
\EndWhile\label{euclidendwhile}
\State \textbf{return} $b$
\EndProcedure
\end{algorithmic}
\end{document}
Basic framework: http://www.texample.net/tikz/examples/filesystem-tree/
Have a look to 21. Making trees grow in PGF Manual.
The solution is my first try with it, so its not perfect.
You can create nodes
and childs
. The distance between the levels can defined with level distance=<length>
.
Connection between node and child it set with edge from parent path={[->] ([xshift=.5em]\tikzparentnode.south west) |- (\tikzchildnode.west)}]
. (The xshift
is optional). You can also add dashed
.
The child position is set with grow via three points={...}
have a look to chapter 72.1 Growth Functions in PGF Manual.
For space/ blank childs you can add child [missing] {}
.
Optional you can set the nodes also to dashed
and not solid
or something else.
MWE:
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{trees}
\begin{document}
\tikzstyle{every node}=[draw=black,thick,anchor=west]
\begin{tikzpicture}[%
parent anchor=south west,
level distance=40mm,
grow via three points={one child at (0.1,-1) and
two children at (0.1,-1) and (0.1,-2)},
%edge from parent path={(\tikzparentnode.south) |- (\tikzchildnode.west)}]
edge from parent path={[->] ([xshift=.5em]\tikzparentnode.south west) |- (\tikzchildnode.west)}]
\node { \_start}
child { node {main}
child[%
grow via three points={one child at (0.1,-1) and
two children at (0.1,-1) and (0.1,-2)},
edge from parent path={[->] ([xshift=.5em]\tikzparentnode.south west) |- (\tikzchildnode.west)}] { node {\_\_function}
child[%
grow via three points={one child at (-0.5,-1) and
two children at (-0.5,-1) and (-1.2,-1)},
edge from parent path={[->] ([xshift=.5em]\tikzparentnode.south west) |- (\tikzchildnode.west)}] { node {\_\_mt\_MasterFunction\_}
child[%
grow=right, edge from parent path={[->,dashed] (\tikzparentnode.east) |- (\tikzchildnode.west)}] { node {\_thread\_start}
child[%
grow via three points={one child at (-0.5,-1) and
two children at (-0.5,-1) and (-0.5,-2)},
edge from parent path={[->,solid] ([xshift=.5em]\tikzparentnode.south west) |- (\tikzchildnode.west)}] { node[solid] {\_\_mt\_SlaveFunction}
child { node {\_\_mt\_WaitForWork}}
child { node {\_\_mt\_run\_my\_job}
child { node {\_\_mt\_runLoop\_int\_}
child { node {loop body function}}
}
}
child [missing] {}
child [missing] {}
child { node {\_\_mt\_EndOfTaskBarrier\_}}
}
}
child { node {\_\_mt\_run\_my\_job\_}
child { node {\_\_mt\_runloop\_int\_}
child { node {loop body function}}
}
}
}
child [missing] {}
child [missing] {}
child [missing] {}
child { node {\_\_mt\_EndOfTaskBarrier\_}}
}
};
\end{tikzpicture}
\end{document}
Best Answer
Store the counter and restore it using TeX's
\label
-\ref
system and the support ofrefcount
:Note that
algorithmicx
provides\algsave
and\algrestore
, specifically for this purpose.