1

I tried to make a UML diagram using I strive in searching to make it looks good. Here is my code, sorry if there are errors (as I am a new learner to TIKZ package) but it should still work if u just copy and paste the code on overleaf. Is there is an efficient way to make the UML diagram much better ? for example: as in the attached image, the highlighted part is not aligned.enter image description here

enter code here\documentclass[tikz,border=3.14mm]{standalone}
    library{positioning,calc,arrows.meta}
     cument}
       picture}

block/.style={rectangle, draw, fill=blue!10, text width=5em, text centered, unded corners} }
      {line} = [draw, -']
 style{arrow} = [draw, -latex']
       *\circled[1]{\tikz[baseline=(char.base)]{\node[shape=circle,draw,inner sep=0.6pt, text width=0.1cm] (char) {#1};}}

    block, text width=3.cm, align=center](man) at (0,0){\textbf{Device A}};
\node[ block, text width=3cm, right= 5 cm of man, align=center](smart) {         Device B}};

\node[ block, text width=3cm, right= 5 cm of smart, align=center](recv) { \textbf{Device C}};

\path[line, line width=0.5mm] (man.south) -- ($(man)+(0,-8)$);
\path[line, line width=0.5mm] (smart.south) -- ($(smart)+(0,-8)$);

\path[line, line width=0.5mm] (recv.south) -- ($(recv)+(0,-8)$);


    \path [arrow, text width=4.5cm, align=left] ($(man)+(0,-0.5)$) -- ++(0.5cm,0cm) |- node[near start, right] { Computes $G^R_0= M^R_0$ \\  Computes $G^R_n = l^R_n$\\ Picks $I^R_0  = t^R_0$} ($(man)+(0,-1.7)$);


    \draw[-{Latex[length=3mm, width=2mm]}] ($(man)+(0,-3)$) to node [above, black]{\Small \texttt{$T(R)=X^R_0, X^R_0, Y^R_d $}} ($(smart)+(0,-3)$);

        \path [arrow, text width=4.5cm, align=left] ($(recv)+(0,-1.5)$) -- ++(0.5cm,0cm) |- node[near start, right] { $Picks Z^R_0 \leftarrow l^R_0$ \\ computes $Z^R_n \leftarrow l^R_n$\\ $I^R_0  \leftarrow t^R_0$} ($(recv)+(0,-2.9)$);

        \draw[-{Latex[length=3mm, width=2mm]}] ($(recv)+(0,-3.8)$) to node [above, black]{\Small \texttt{$S^{D_1}_0, S^{D_1}_n, t^{D_1}_0, t^{M_1}_n, F_{M_1}] $}} ($(smart)+(0,-3.8)$);

\path [arrow, text width=4.5cm, align=left] ($(smart)+(0,-4.5)$) -- ++(0.5cm,0cm) |- node[near start, right] { $Picks Z^R_0 \leftarrow l^R_0$ \\ computes $Z^R_n \leftarrow l^R_n$\\ $I^R_0  \leftarrow t^R_0$} ($(smart)+(0,-5.9)$);
  ikzpicture}
 document}

1 Answer 1

2

Something seems to have gone wrong when you copied the code. I tried to restore the code and align the objects in a table.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning,calc,arrows.meta}
\begin{document}
\begin{tikzpicture}[%
block/.style={rectangle, draw, fill=blue!10, text width=5em, text centered,
rounded corners},line/.style={draw, -latex},arrow/.style={draw, -latex}]

  \node[block,text width=3.cm, align=center,font=\bfseries](man) at (0,0){Device A};
  \node[block,text width=3cm,right=5cm of man, align=center,font=\bfseries](smart) {Device B};
  \node[block,text width=3cm,right=5cm of smart,align=center,font=\bfseries](recv) {Device C};

  \path[line, line width=0.5mm] (man.south) -- ($(man)+(0,-8)$);
  \path[line, line width=0.5mm] (smart.south) -- ($(smart)+(0,-8)$);
  \path[line, line width=0.5mm] (recv.south) -- ($(recv)+(0,-8)$);

  \path [arrow, text width=4.5cm, align=left] ($(man)+(0,-0.5)$) -- ++(0.5cm,0cm) |- node[near start, right] { 
  \begin{tabular}{ll}
   Computes & $G^R_0= M^R_0$ \\  Computes & $G^R_n = l^R_n$\\ Picks & $I^R_0  = t^R_0$
   \end{tabular}} ($(man)+(0,-1.7)$);
  \draw[-{Latex[length=3mm, width=2mm]}] ($(man)+(0,-3)$) to node [above, black]{$T(R)=X^R_0, X^R_0, Y^R_d $} ($(smart)+(0,-3)$);
  \path [arrow, text width=4.5cm, align=left] ($(recv)+(0,-1.5)$) -- ++(0.5cm,0cm) |- node[near start, right] 
  {\begin{tabular}{ll}
    Picks & $Z^R_0 \leftarrow l^R_0$ \\ 
    computes & $Z^R_n \leftarrow l^R_n$\\ 
    & $I^R_0  \leftarrow t^R_0$
    \end{tabular}} ($(recv)+(0,-2.9)$);
  \draw[-{Latex[length=3mm, width=2mm]}] ($(recv)+(0,-3.8)$) to 
  node[above, black]{$S^{D_1}_0, S^{D_1}_n, t^{D_1}_0, t^{M_1}_n, F_{M_1}$} ($(smart)+(0,-3.8)$);
  \path [arrow, text width=4.5cm, align=left] ($(smart)+(0,-4.5)$) 
  -- ++(0.5cm,0cm) |- node[near start, right] {
  \begin{tabular}{ll}
   Picks & $Z^R_0 \leftarrow l^R_0$ \\ 
   computes &  $Z^R_n \leftarrow l^R_n$\\ 
   & $I^R_0  \leftarrow t^R_0$
  \end{tabular}} ($(smart)+(0,-5.9)$);
\end{tikzpicture}
\end{document}

enter image description here

5
  • Thanks so much. do you know how to add \point command so I can enumerate/itemize elements that are inside tabular ? Commented Feb 16, 2019 at 1:24
  • @HebaMohsen You could just add \textbullet\ before the items.
    – user121799
    Commented Feb 16, 2019 at 1:25
  • How can I reduce the size of \textbullet\ as it seems the default one is too big? Commented Feb 16, 2019 at 1:29
  • 1
    @HebaMohsen I am not really online now. Try \scalebox{0.5}{\textbullet}. No guarantee that it works. You can always ask a new question, it's free of charge.
    – user121799
    Commented Feb 16, 2019 at 2:23
  • it works very well Commented Feb 16, 2019 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .