我想像图片中那样绘制方框,但顺序相同。因此,我创建了一个表格,并在表格的列中添加了方框,但没有成功。另外,我不希望箭头上的文本与方框交织在一起(例如,如第 3 个方框)。
这是我的代码。
\documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{tabularx}
\usepackage{tikz}
\usepackage{flowchart}
\usetikzlibrary{arrows}
\newcommand{\GCinp}{\ensuremath{\mathsf{GC}_I}}
\newcommand{\GCout}{\ensuremath{\mathsf{GC}_O}}
\newcommand{\GCnorm}{\ensuremath{\mathsf{GC}_N}}
\newcommand{\GC}{\ensuremath{\mathsf{GC}}}
%algorithms
\newcommand{\genEqCons}{\texttt{GenEqConst}}
\newcommand{\genEqNum}{\texttt{GenEqNumbers}}
\newcommand{\genKeys}{\texttt{GenKeys}}
\newcommand{\comInput}{\texttt{CommitInput}}
\newcommand{\genOutput}{\texttt{GenOutputNums}}
\newcommand{\genGC}{\texttt{ConstructGC}}
\newcommand{\getEqNum}{\texttt{GetEqNumbers}}
%sets
\newcommand{\seteconst}{\ensuremath{\mathcal{E}}}
\newcommand{\setenum}{\ensuremath{\mathcal{M}}}
\newcommand{\setirand}{\ensuremath{\mathcal{U}}}
\newcommand{\setKeys}{\ensuremath{\mathcal{K}}}
\newcommand{\setpartdecom}{\ensuremath{\mathcal{R}}}
\newcommand{\setinpCom}{\ensuremath{\mathcal{D}}}
\newcommand{\setrandRow}{\ensuremath{\mathcal{P}}}
\newcommand{\setcomRandRow}{\ensuremath{\mathcal{S}}}
\newcommand{\setoutput}{\ensuremath{\mathcal{O}}}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{figure}
\begin{center}
\begin{scriptsize}
\begin{tabular}{R{5cm} C{5cm} L{5cm}}
&\textbf{S2PC phase} &\\
$ \{m_{i,x_i}\}_{i = 1} ^\ell \leftarrow $ \getEqNum($x, \setenum_a$) & $\xrightarrow[\hspace{4cm}]{\GC_a, \{m_{i,x_i}\}_{i = 1} ^\ell , \setinpCom,\setcomRandRow} $ & \\
& $\xleftarrow[\hspace{4cm}]{\GC_b, \{m_{i,y_i}\}_{i = 1} ^\ell , \setinpCom',\setcomRandRow'} $ & $ \{m'_{i,y_i}\}_{i = 1} ^\ell \leftarrow $ \getEqNum($y, \setenum'_b$) \\
& \begin{tikzpicture}[>=stealth, thick, scale = 0.6]
\node (A) at (0,0) [draw, process, text width=1.5cm, minimum height=1cm, align=flush center]
{Check Correctness};
\coordinate (B) at (4,0.54);
\coordinate (C) at (4,-0.48);
\coordinate (D) at (-4,0);
\coordinate (E) at (-4,0);
\draw[->] (D) -- node[above] {\setcomRandRow,\setirand} (A);
\draw[->] (A.-18) -- node[below]{0/1}(C);
\draw[->] (B) -- node[above] {\setinpCom,\setcomRandRow} (A.20);
\end{tikzpicture}& \\
& \begin{tikzpicture}[>=stealth, thick, scale = 0.6]
\node (A) at (0,0) [draw, process, text width=1.5cm, minimum height=1cm, align=flush center]
{Check Correctness};
\coordinate (B) at (4,0.0);
\coordinate (C) at (4,0);
\coordinate (D) at (-4,0.54);
\coordinate (E) at (-4,-0.6);
\draw[->] (A.203) -- node[above] {0/1} (E);
\draw[->] (B) -- node[below]{\setcomRandRow',\setirand'}(A);
\draw[->] (D) -- node[above] {\setinpCom',\setcomRandRow'} (A.160);
\end{tikzpicture}& \\
& \begin{tikzpicture}[>=stealth, thick, scale = 0.6]
\node (A) at (0,0) [draw, process, text width=1.5cm, minimum height=1cm, align=flush center]
{S2PC ($\GC_a$)};
\coordinate (B) at (4,0.54);
\coordinate (C) at (4,-0.48);
\coordinate (D) at (-4,0);
\coordinate (E) at (-4,0);
\draw[->] (D) -- node[above] {$ x $} (A);
\draw[->] (A.-18) -- node[below]{\setoutput$ _a, \{m_{i,y_i}\}_{i=1}^\ell $}(C);
\draw[->] (B) -- node[above] {$ y $} (A.20);
.160);
\end{tikzpicture}& \\
& \begin{tikzpicture}[>=stealth, thick, scale = 0.6]
\node (A) at (0,0) [draw, process, text width=1.5cm, minimum height=1cm, align=flush center]
{S2PC ($\GC_b$)};
\coordinate (B) at (4,0.0);
\coordinate (C) at (4,0);
\coordinate (D) at (-4,0.54);
\coordinate (E) at (-4,-0.6);
\draw[->] (A.203) -- node[below] {$ \setoutput'_b, \{m'_{i,x_i}\}_{i=1}^\ell$} (E);
\draw[->] (B) -- node[below]{$ y $}(A);
\draw[->] (D) -- node[above] {$ x $} (A.160);
\end{tikzpicture}& \\
\end{tabular}
\end{scriptsize}
\end{center}
\end{figure}
\end{document}
答案1
尝试
\documentclass{article}
\usepackage{amsfonts,amsmath}
% \usepackage{tabularx}
\usepackage{tikz}
\usetikzlibrary{arrows,chains,positioning}% <-- added libraries
% \usepackage{flowchart}
\usepackage[active,floats,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{1em}
\newcommand{\GCinp}{\ensuremath{\mathsf{GC}_I}}
\newcommand{\GCout}{\ensuremath{\mathsf{GC}_O}}
\newcommand{\GCnorm}{\ensuremath{\mathsf{GC}_N}}
\newcommand{\GC}{\ensuremath{\mathsf{GC}}}
%algorithms
\newcommand{\genEqCons}{\texttt{GenEqConst}}
\newcommand{\genEqNum}{\texttt{GenEqNumbers}}
\newcommand{\genKeys}{\texttt{GenKeys}}
\newcommand{\comInput}{\texttt{CommitInput}}
\newcommand{\genOutput}{\texttt{GenOutputNums}}
\newcommand{\genGC}{\texttt{ConstructGC}}
\newcommand{\getEqNum}{\texttt{GetEqNumbers}}
%sets
\newcommand{\seteconst}{\ensuremath{\mathcal{E}}}
\newcommand{\setenum}{\ensuremath{\mathcal{M}}}
\newcommand{\setirand}{\ensuremath{\mathcal{U}}}
\newcommand{\setKeys}{\ensuremath{\mathcal{K}}}
\newcommand{\setpartdecom}{\ensuremath{\mathcal{R}}}
\newcommand{\setinpCom}{\ensuremath{\mathcal{D}}}
\newcommand{\setrandRow}{\ensuremath{\mathcal{P}}}
\newcommand{\setcomRandRow}{\ensuremath{\mathcal{S}}}
\newcommand{\setoutput}{\ensuremath{\mathcal{O}}}
%\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
%\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
%\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{tikzpicture}[>=stealth, thick,
node distance = 5mm and 24mm,
start chain = going below,
box/.style = {name=#1,
draw, align=flush center,
text width=22mm, minimum height=9mm, inner sep=1mm,
on chain},
u/.style = {yshift=#1 mm}]
%---
\linespread{0.8}
%--- boxes
\node[box=A] {Check Correctness};
%---
\coordinate[left =of A] (Aleft);
\coordinate[right=of A] (Aright);
\draw[->] (Aleft) to node[above] {\setcomRandRow,\setirand} (A);
\draw[->] ([u=+2] A.east)
to node[above] {\setinpCom,\setcomRandRow} ([u=+2] Aright);
\draw[->] ([u=-2] A.east) to node[below] {0/1} ([u=-2] Aright);
%---
\node[box=B] {Check Correctness};
\draw[->] ([u=+2] Aleft |- B) to node[above] {0/1} ([u=+2] B.west);
\draw[<-] ([u=-2] Aleft |- B)
to node[below]{\setcomRandRow',\setirand'} ([u=-2] B.west);
\draw[->] (B) to node[above] {\setinpCom',\setcomRandRow'} (B -| Aright);
%---
\node[box=C] {S2PC ($\GC_a$)};
\draw[->] (Aleft |- C) to node[above] {$x$} (C);
\draw[->] ([u=+2] C.east) to node[above] {$y$} ([u=+2] C -| Aright);
\draw[->] ([u=-2] C.east)
to node[below] {\setoutput$_a,\{m_{i,y_i}\}_{i=1}^\ell $}
([u=-2] C -| Aright);
%---
\node[box=D] {S2PC ($\GC_b$)};
\draw[->] ([u=+2] Aleft |- D.west) to node[above] {$x$} ([u=+2] D.west);
\draw[<-] ([u=-2] Aleft |- D.west)
to node[below] {$\setoutput'_b,\{m'_{i,x_i}\}_{i=1}^\ell$} ([u=-2] D.west);
\draw[<-] (D) to node[above] {$y$} (D -| Aright);
%--- top of picture
\node[align=center,above=of A] (E)
{
$\xrightarrow[\hspace{42mm}]
{\GC_a,\{m_{i,x_i}\}_{i=1}^\ell,\setinpCom,\setcomRandRow}$\\
$\xleftarrow[\hspace{42mm}]
{GC_b,\{m_{i,y_i}\}_{i = 1}^\ell,\setinpCom',\setcomRandRow'}$
};
\node[left =0mm of E]
{$\{m_{i,x_i}\}_{i=1}^\ell\leftarrow\text{\getEqNum}(x,\setenum_a)$};
\node[right=0mm of E]
{$\{m'_{i,x_i}\}_{i=1}^\ell\leftarrow\text{\getEqNum}(x,\setenum'_b)$};
\node[above=of E] (F) {\textbf{S2PC phase}};
\end{tikzpicture}
\end{document}
据我所知,提供的图片无需 tabular(x) 环境即可实现。因此,我从您的代码中省略了所有与 tabular 环境相关的内容。对于图片合成,我使用了额外的 TikZ 库(链、定位)。