我尝试使用 msc 包,但它遇到了很多问题。这就是为什么我决定像下面这样绘制它。
我的代码:
%!TEX TS-program = pdflatex
\documentclass[border=1mm,tikz]{standalone}
\usetikzlibrary{positioning,calc}%to use righ=of
\begin{document}
\def\nodeTextWidth{4.5cm}
\def\levelOne{2cm}
\begin{tikzpicture}[
node distance=7mm and 5mm,
every node/.append style={very thick},
entity/.style={draw, rectangle, minimum width=\nodeTextWidth},
hiddenentity/.style={,rectangle, minimum width=\nodeTextWidth},
operation/.style={draw=black,thick,fill=white,rounded corners=0mm,text width=\nodeTextWidth,font=\scriptsize, inner sep=2pt, text centered},
myarrow/.style={line width=2pt,black,-latex},
textAboveArrow/.style={inner sep=2pt,outer sep=4pt, fill=white,font=\footnotesize}
]
\node[entity] (bank) {Eve};
\node[entity, right=of bank] (smartMeter) {Alice};
\node[entity, right=of smartMeter] (utilityProvider) {Bob};
\node[operation, below=of bank] (accountDescription) { $xxxxxxx$};
%VERTICAL LINES
\draw [very thick] (bank) -- (accountDescription)--(0,-11);
\node[mark size=3pt,color=black] at (0,-11) {\pgfuseplotmark{*}};
\draw [very thick] (smartMeter)--++(0,-11);
\node[mark size=3pt,color=black] at (\nodeTextWidth+5.5mm,-11) {\pgfuseplotmark{*}};
\draw [very thick] (utilityProvider)--++(0,-11);
\node[mark size=3pt,color=black] at (\nodeTextWidth*2+11mm,-11) {\pgfuseplotmark{*}};
%=============================== AUTHENTICATION PHASE =======================
%LEVEL ONE COMMUNICATION
\node[hiddenentity,below=of accountDescription](bankL2){};
\node[hiddenentity,right=of bankL2](SML2){};
%
\draw [myarrow] (bankL2.center)--(SML2.center) node[textAboveArrow,above,midway] {$xxxxxxx$};
\node[hiddenentity,below=of SML2](SML3){};
\node[hiddenentity,right=of SML3](UPL3){};
\draw [myarrow] (SML3.center)--(UPL3.center) node[textAboveArrow,above,midway] {$xxxxxxx$};
\node[hiddenentity,below=of SML3](SML4){};
\node[hiddenentity,right=of SML4](UPL4){};
\draw [myarrow] (UPL4.center)--(SML4.center) node[textAboveArrow,above,midway] {$xxxxxxx$};
\node[operation, below=of SML4] (findSigma) {Find the value of $xxxxxxx$};
\node[hiddenentity,right=of findSigma](UPL5){};
\draw[thick] ($(accountDescription.north west)+(-0.1,0.15)$) rectangle ($(UPL5.south east)+(0.1,-0.25)$) node[below=2.5mm of smartMeter,fill=white, draw, rectangle]{\textit{First Phase}} ;
%======================== REPORTING PHASE ===============================
\node[hiddenentity,below=of findSigma](SML6){};
\node[hiddenentity,left=of findSigma](BL6){};
\node[hiddenentity,below=of BL6](BL7){};
\node[hiddenentity,right=of SML6](UPL6){};
\draw [myarrow] (SML6.center)--(UPL6.center) node[textAboveArrow,above,midway] {xxxxxxx};
\node[operation, below=of UPL6] (recordPayment) {xxxxxxx};
\draw[thick] ($(BL7.north west)+(-0.1,0.25)$) rectangle ($(recordPayment.south east)+(0.1,-0.1)$) node[below=2.5mm of BL6,fill=white, draw, rectangle, rounded corners=0mm]{\textit{Second Phase}} ;
%==================== REWARDING PHASE ========================
\node[hiddenentity,below=of recordPayment](UPL8){};
\node[hiddenentity,left=of UPL8](SML8){};
\node[hiddenentity,left=of SML8](BL8){};
\draw [myarrow] (SML8.center)--(UPL8.center) node[textAboveArrow,above,midway] {xxxxxxx};
\node[hiddenentity,below=of UPL8](UPL9){};
\node[hiddenentity,left=of UPL9](SML9){};
\node[hiddenentity,left=of SML9](BL9){};
\draw [myarrow] (UPL9.center)--(BL9.center) node[textAboveArrow,above,midway] {xxxxxxx};
\draw[thick] ($(BL8.north west)+(-0.15,0.5)$) rectangle ($(UPL9.south east)+(0.15,-0.1)$) node[below=16mm of BL7,fill=white, draw, rectangle]{\textit{Third Phase}} ;
\end{tikzpicture}
\end{document}
我有两个主要问题:
首要问题: 当使用 pdflatex 进行编译时,它显示正确的输出如下(第三阶段定位不正确):
但是,当我用 xelatex(我的论文需要)编译它时,垂直线末尾的圆圈消失了,如下所示。
第二个问题:
有没有更好的方法可以在一组节点周围绘制矩形,并创建一个标签,如 (第一阶段、第二阶段和第三阶段),使用相对定位居中。第三阶段的定位应与第二阶段的定位类似。
答案1
以下代码已使用 xelatex 编译。我不知道 plotmarks 出了什么问题,但我已将它们替换为-{Circle[]}
箭头(arrows.meta
库),它们又可以显示了。
我还对您的代码做了一些其他更改。主要是我只hiddenentity
在需要时使用节点。我已将它们替换为coordinate
节点。
相位矩形已被fit
节点取代。为了保持对称性,hiddenentity
使用了一些节点。
\documentclass[border=1mm,tikz]{standalone}
\usetikzlibrary{positioning,calc, arrows.meta, fit}%to use righ=of
\begin{document}
\def\nodeTextWidth{4.5cm}
\def\levelOne{2cm}
\begin{tikzpicture}[
node distance=7mm and 5mm,
every node/.append style={very thick},
entity/.style={draw, rectangle, minimum width=\nodeTextWidth},
hiddenentity/.style={,rectangle, minimum width=\nodeTextWidth},
operation/.style={draw=black,thick,fill=white,rounded corners=0mm,text width=\nodeTextWidth,font=\scriptsize, inner sep=2pt, text centered},
myarrow/.style={line width=2pt,black,-latex},
textAboveArrow/.style={inner sep=2pt,outer sep=4pt, fill=white,font=\footnotesize}
]
\node[entity] (bank) {Eve};
\node[entity, right=of bank] (smartMeter) {Alice};
\node[entity, right=of smartMeter] (utilityProvider) {Bob};
\node[operation, below=of bank] (accountDescription) { $xxxxxxx$};
%VERTICAL LINES
\draw [very thick, -{Circle[]}] (bank) -- (accountDescription)--(0,-11);
% \node[mark size=3pt,color=black] at (0,-11) {\pgfuseplotmark{*}};
\draw [very thick, -{Circle[]}] (smartMeter)--++(0,-11);
% \node[mark size=3pt,color=black] at (\nodeTextWidth+5.5mm,-11) {\pgfuseplotmark{*}};
\draw [very thick, -{Circle[]}] (utilityProvider)--++(0,-11);
% \node[mark size=3pt,color=black] at (\nodeTextWidth*2+11mm,-11) {\pgfuseplotmark{*}};
%=============================== AUTHENTICATION PHASE =======================
%LEVEL ONE COMMUNICATION
% \node[hiddenentity,below=of accountDescription](bankL2){};
\coordinate[below=of accountDescription] (bankL2);
\draw[myarrow] (bankL2)--(bankL2-|smartMeter) coordinate (SML2) node[textAboveArrow,above,midway] {$xxxxxxx$};
% \node[hiddenentity,right=of bankL2](SML2){};
% %
% \draw [myarrow] (bankL2.center)--(SML2.center) node[textAboveArrow,above,midway] {$xxxxxxx$};
\coordinate[below=of SML2](SML3);
% \node[hiddenentity,right=of SML3](UPL3){};
\draw [myarrow] (SML3)--(SML3-|utilityProvider) coordinate(UPL3) node[textAboveArrow,above,midway] {$xxxxxxx$};
\coordinate[below=of UPL3](UPL4){};
% \node[hiddenentity,right=of SML4](UPL4){};
\draw [myarrow] (UPL4)--(UPL4-|SML3) coordinate (SML4) node[textAboveArrow,above,midway] {$xxxxxxx$};
\node[operation, below=of SML4] (findSigma) {Find the value of $xxxxxxx$};
\node[hiddenentity,right=of findSigma](UPL5){};
\node[fit=(accountDescription) (UPL5), draw, thick, label={[font=\itshape, fill=white, draw, anchor=center]90:First Phase}] {};
% \draw[thick] ($(accountDescription.north west)+(-0.1,0.15)$) rectangle ($(UPL5.south east)+(0.1,-0.25)$) node[below=2.5mm of smartMeter,fill=white, draw, rectangle]{\textit{First Phase}} ;
%======================== REPORTING PHASE ===============================
\coordinate[below=12mm of findSigma](SML6);
\draw [myarrow] (SML6)--(SML6-|UPL4) coordinate (UPL6) node[textAboveArrow,above,midway] (text6) {xxxxxxx};
\node[hiddenentity] at (SML6-|bankL2) (BL6) {};
% \node[hiddenentity,below=of BL6] (BL7){};
% \node[hiddenentity,right=of SML6](UPL6){};
\node[operation, below=of UPL6] (recordPayment) {xxxxxxx};
\node[fit=(BL6) (recordPayment) (text6), draw, thick, label={[font=\itshape, fill=white, draw, anchor=center]90:Second Phase}] {};
% \draw[thick] ($(BL7.north west)+(-0.1,0.25)$) rectangle ($(recordPayment.south east)+(0.1,-0.1)$) node[below=2.5mm of BL6,fill=white, draw, rectangle, rounded corners=0mm]{\textit{Second Phase}} ;
%==================== REWARDING PHASE ========================
\coordinate[below=12mm of recordPayment](UPL8);
\draw [myarrow] (UPL8-|SML6)--(UPL8) node[textAboveArrow,above,midway] (text8) {xxxxxxx};
% \node[hiddenentity,left=of UPL8](SML8){};
% \node[hiddenentity,left=of SML8](BL8){};
% \draw [myarrow] (SML8.center)--(UPL8.center) node[textAboveArrow,above,midway] {xxxxxxx};
\coordinate[below=of UPL8] (UPL9);
\draw [myarrow] (UPL9)--(UPL9-|bankL2) node[textAboveArrow,above,midway] {xxxxxxx};
\node[hiddenentity] at (bankL2|-UPL8) (BL8) {};
\node[hiddenentity] at (UPL9) (UPL9aux) {};
% \node[hiddenentity,left=of SML9](BL9){};
% \draw [myarrow] (UPL9.center)--(BL9.center) node[textAboveArrow,above,midway] {xxxxxxx};
\node[fit=(BL8) (UPL9aux) (text8), draw, thick, label={[font=\itshape, fill=white, draw, anchor=center]90:Third Phase}] {};
% \draw[thick] ($(BL8.north west)+(-0.15,0.5)$) rectangle ($(UPL9.south east)+(0.15,-0.1)$) node[below=16mm of BL7,fill=white, draw, rectangle]{\textit{Third Phase}} ;
\end{tikzpicture}
\end{document}