如何在 TikZ 中的节点下方绘制箭头?

如何在 TikZ 中的节点下方绘制箭头?

我想使用 Beamer 中的 TikZ 复制以下绘图,并对名称进行略微更改。

在此处输入图片描述

目前,我有类似的东西,但这不是我想要的。线条在节点旁边而不是下面,而且我不知道如何在节点下面写东西并在那里放箭头。最初在幻灯片中应该只有节点和节点下面和上面的文本。然后,在下一个转换中应该出现带有 PreSign 的线条,然后是从右到左的箭头,然后是带有 Adapt 的线条,然后是从左到右的箭头,最后是带有 Ext 的线条。我如何使用 TikZ 实现这一点?

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{
    arrows,
    calc,
    chains,
    decorations,
    decorations.text,
    decorations.pathmorphing,
    matrix,
    positioning,
    shapes,
    tikzmark
}
\usepackage{tikzpeople}

\begin{document}

\begin{frame}{Protocol View}
\begin{tikzpicture}[node distance=5cm]
% nodes
\node[alice,minimum size=1.5cm] (s) at (0,0) {$(Y,y) \in R$};
\node[bob,minimum size=1.5cm,right of=s] (r) {$(\mathsf{pk},\mathsf{sk})$};
% paths
\draw [->] (r) -- node [text width=2.5cm,midway,above,align=center] {$\hat{\sigma}$} (s);
\draw [->] ($(s.east)+(1em,-1em)$) -- node [text width=2.5cm,midway,above,align=center] {$\sigma$} ($(r.west)+(-1em,-1em)$);
\end{tikzpicture}
\end{frame}

\end{document}

答案1

与 一起使用matrix(或) 。tikz-cdoverlay-beamer-styles

\documentclass{beamer}

\usepackage{tikz}
\usetikzlibrary{
    matrix,
    overlay-beamer-styles
}
\usepackage{tikzpeople}

\begin{document}

\begin{frame}
\frametitle{Protocol View}
\begin{tikzpicture}[ar/.style={very thick,-latex},nodes={font=\small}]

\matrix[column sep=1.8cm,matrix of math nodes,
ampersand replacement=\&,
row 3/.style={nodes={visible on=<2->}},
row 4/.style={nodes={visible on=<4->}},
row 5/.style={nodes={visible on=<6->}}]  (m) {
|[alice,minimum size=1.5cm]| (Y,y) \in R \&
|[bob,minimum size=1.5cm]| (\mathsf{pk},\mathsf{sk})\\
pk,M \& y,M\\
\& \hat\sigma\leftarrow\operatorname{PreSign}\bigl((pk,sk),y,M\bigr)\\
\sigma\leftarrow\operatorname{Adap}\bigl((Y,y),p,k,M\bigr) \&\\
\& y'\leftarrow\operatorname{Ext}(y,\hat\sigma,\sigma)\\
};
\path (m-3-2.south west) -- coordinate (p1) (m-3-2.west|-m-4-1.north)
 (m-5-2.north west) -- coordinate (p2) (m-5-2.west|-m-4-1.south);
\draw[ar,visible on=<5->] (p1) -- node[above]{$\hat\sigma$} (p1-|m-4-1.east);
\draw[ar,visible on=<7->] (p2-|m-4-1.east) -- node[above]{$\sigma$} (p2);
\end{tikzpicture}
\end{frame}
\end{document}

在此处输入图片描述

相关内容