我想使用 绘制类似于下图的东西tikzpicture
。我成功地绘制了箭头,但我无法在箭头开头放数字。我使用了这个想法绘制网络协议绘制箭头。
你能帮我吗?谢谢!
下面您可以看到我所做的一切。
\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}
答案1
您可以直接使用节点。这是一个模仿您的图表的解决方案,使用临时节点将元素相对放置:
\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}
输出