# Adding circled numbers to beginning of the arrow using tikzpicture

I would like to draw something similar to the following image using tikzpicture. I succeed in drawing the arrows but I could not put numbers at the beginning of them. I used the idea in Drawing network protocols to draw the arrows.

Can you help me about it? Thanks!

Below you can see what I have done.

\begin{tikzpicture}
\tikzstyle{every node}=[font=\tiny]
\matrix (m)[matrix of nodes, column  sep=2cm,row  sep=8mm, nodes={draw=none, anchor=center,text depth=0pt} ]{
{\normalsize \textbf{$P_i$}} & $(pk,v,g, \Z_p, t_1, t_2, id)$ and names of parties are public  & {\normalsize \textbf{$P_j$}}\\[-4mm]
$x_i\in_r \Z_p$ & & $x_j\in_r \Z_p$ \\[-7mm]
& $h_i=g^{x_i}$, $PK log(g,h)\{\xi: h=g^{\xi}\}$ & \\
$h = \sum g^{x_i} = g^x$ & $h_j=g^{x_j}$, $PK log(g,h)\{\xi: h=g^{\xi}\}$ &   $h = \sum g^{x_i} = g^x$ \\
& \textbf{. . . . . . . . . . . . . . . . . . . . . . . . . . . . .} & \\

$r_i \in \Z_p$  & $V^1_i = VE((g^{r_i},s_ih^{r_i}), h;\emptyset)\{(v_i,s_i)\in R\}$ &

\\ };

\draw[shorten <=-1cm,shorten >=-1cm] (m-1-1.south east)--(m-1-1.south west){};
\draw[shorten <=-1cm,shorten >=-1cm] (m-1-3.south east)--(m-1-3.south west);
\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-3-2.south west)--(m-3-2.south east);
\draw[shorten <=-1cm,shorten >=-1cm,-latex](m-4-2.south east)--(m-4-2.south west);

\draw[shorten <=-1cm,shorten >=-1cm,-latex] (m-6-2.south west)--(m-6-2.south east);

\end{tikzpicture}

• Can you show us what you have tried? – Andrew Swann May 13 '14 at 13:06
• I add what I did – user1914367 May 13 '14 at 13:19
• @user1914367: the best approach would be to add a couple of columns (one at the beginning and one at the end) of the matrix in which you could put numbers (i.e. |[circle,inner sep=1pt]|1). BTW: welcome to TeX.SX! – Claudio Fiandrino May 13 '14 at 13:23
• Yes I tried it, but in this case the numbers looks far from the arrows. Thanks. – user1914367 May 13 '14 at 14:03

You could use nodes directly. Here is a solution which mimics your diagram, using temporary nodes to place the elements relatively to each other :

\begin{tikzpicture}
\tikzstyle{empty node}=[draw=none, inner sep = 0pt, outer sep = 0pt]
\tikzstyle{arrow start}=[draw, circle, inner sep = 1pt]

%move these node to modify the width of the diagram
\draw[draw=none]
(0,0) %set here the start x position for arrows
node (startPos) {}
++(-1,0) node[empty node] (dashedStartPos) {} %set here the left dash offset
(10,0) %set here the end x position for arrows
node (endPos) {}
++( 1,0) node[empty node] (dashedEndPos) {} %set here the right dash offset
;

\draw (dashedStartPos) node {Alice} ;
\draw (dashedEndPos) node {Bob} ;

%left to right arrow
\newcommand{\leftToRight}[4][tmp]{
\draw[-latex]
(startPos) ++(0,#2)
node[arrow start] (#1 1) {#3}
(endPos) ++(0,#2)
node[empty node] (#1 2) {}
(#1 1)
-- node[midway, above] {#4}
(#1 2)
;
}

%right to left arrow
\newcommand{\rightToLeft}[4][tmp]{
\draw[-latex]
(endPos) ++(0,#2)
node[arrow start] (#1 2) {#3}
(startPos) ++(0,#2)
node[empty node] (#1 1) {}
(#1 2)
-- node[midway, above] {#4}
(#1 1)
;
}

%dashed line
\newcommand{\dashedLine}[1]{
\draw[dashed]
(dashedStartPos) ++(0,#1)
node[empty node] (tmp1) {}
(dashedEndPos) ++(0,#1)
node[empty node] (tmp2) {}
(tmp1) -- (tmp2)
;
}

%example diagram
%arrows
\leftToRight{-1}{1}{arrow 1}
\rightToLeft{-2}{2}{arrow 2}
%dashed line
\dashedLine{-3}
%more arrows
\rightToLeft[loopStart]{-4}{4}{arrow 3}
\leftToRight{-5}{1}{arrow 6}
\rightToLeft{-6}{2}{arrow 7}
\leftToRight[loopEnd]{-7}{5}{arrow 8}

%side note
\draw[draw = none]
(startPos)
-- node[midway] (notePos) {}
(dashedStartPos)
(loopEnd 1)
-| node[midway] (noteStart) {}
(notePos)
(loopStart 1)
-| node[midway] (noteEnd) {}
(notePos)
;
\draw[-latex]
(noteStart) -- ++(-5mm,0)
|- node[pos = 0.25, text width=2cm, left, text centered] {
repeat for multiple files
}
(noteEnd)
;

\end{tikzpicture}


And the output