8

Given the MWE below from Configure arrows in pgf-umlsd (compiled version on the link) :

\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\usepackage[underline=false]{pgf-umlsd}
\begin{document}

\begin{figure}[H]
    \centering
    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \mess[1]{c}{Longer label}{s}
        \mess[1]{s}{label}{c}
        \mess[1]{c}{label}{s}
        \mess[1]{s}{Longer label}{c}
    \end{sequencediagram}
    \caption{Client-Server messaging}
\end{figure}
\end{document}

I would like to add some "processing contents" on the left of the left dotted vertical bar and on the right of the right dotted vertical bar. (If possible to add some \newline inside of these "processing contents" also)


Text example "linearised"* :

        Client          Server
      c^2 | --------------->| init
          |                 | f=f(c^2)
   g=g(f) | <---------------| f
        g | --------------->| check if h=g
          | <---------------| OK

*What I mean is that I still want to use the above tex form, which has a nice rendering.

The only thing I would like to add are information on both sides at every start and end of an arrow. I am looking for a simple solution if it is possible.

Thank you in advance for any help you may provide.

enigmator
  • 479

1 Answers1

3

I found the definition of \mess in the style, and adapted it as \bloodymess that has three additional arguments at the end. Mandatory arguments 4, 5, and 6 are now: the arrow direction (L, or R); the start note; and the end note. If the arrow direction is given as anything other than L or R, the text will print out directly over the beginning or end of the arrow, respectively

\documentclass{article}
\usepackage{float}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\usepackage[underline=false]{pgf-umlsd}
% message between threads
% Example:
% \bloodymess[delay]{sender}{message content}{receiver}{DIR}{start note}{end note}
\newcommand{\bloodymess}[7][0]{
  \stepcounter{seqlevel}
  \path
  (#2)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
  \addtocounter{seqlevel}{#1}
  \path
  (#4)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
  \draw[->,>=angle 60] (mess from) -- (mess to) node[midway, above]
  {#3};

  \if R#5
    \node (#3 from) at (mess from) {\llap{#6~}};
    \node (#3 to) at (mess to) {\rlap{~#7}};
  \else\if L#5
         \node (#3 from) at (mess from) {\rlap{~#6}};
         \node (#3 to) at (mess to) {\llap{#7~}};
       \else
         \node (#3 from) at (mess from) {#6};
         \node (#3 to) at (mess to) {#7};
       \fi
  \fi
}
\begin{document}

\begin{figure}[H]
    \centering
    \begin{sequencediagram}
        \newinst{c}{Client}
        \newinst[6]{s}{Server}

        \bloodymess[1]{c}{Longer label}{s}{R}{Start}{Server receives}
        \bloodymess[1]{s}{label}{c}{L}{Server responds}{}
        \bloodymess[1]{c}{label}{s}{R}{2nd handshake begins}{}
        \bloodymess[1]{s}{Longer label}{c}{L}{}{End}
    \end{sequencediagram}
    \caption{Client-Server messaging}
\end{figure}
\end{document}

enter image description here

  • This was helpful. Thanks. But when I try to write label with brackets, e.g. X=F(Y), I get lots of errors. Can you please help? – user2192774 Apr 07 '16 at 16:46
  • @user2192774 I found I can use parens or brackets (not braces) by enclosing the math argument in an extra set of braces: \bloodymess[1]{s}{{$x = f[y]$}}{c}{L}{Server responds}{}. Alternately, changing every instance of #3 to {#3} in the definition of \bloodymess will allow math labels to be specified directly, without the double embrace. – Steven B. Segletes Apr 07 '16 at 16:52
  • Thanks but I need braces (i.e. round brackets). How can I do this? – user2192774 Apr 07 '16 at 16:55
  • One more thing plz. If I want to make the side comments to be itemized (list). It gives me error. This is one line that does not work: \bloodymess[1]{s}{{$x = E_k(N_v)$}}{c}{R}{\begin{itemize} \item ee \end{itemize}}{} – user2192774 Apr 07 '16 at 18:31
  • or at least, just how to add several lines in the side comment? when I try \\, I get error. Thanks. – user2192774 Apr 07 '16 at 18:41
  • @user2192774 You can put the side comment in a \parbox, for example, \bloodymess[1]{c}{label}{s}{R}{\parbox{1in}{2nd handshake begins}}{} – Steven B. Segletes Apr 07 '16 at 18:44
  • @user2192774 Alternately, you could place \usepackage{stackengine}\setstackEOL{\\} in your preamble, and then for the multiline comment, \bloodymess[1]{c}{label}{s}{R}{\Longstack[r]{2nd handshake\\ begins}}{} where the [r] is right-alignment, and could also be set to [l] or [c]. – Steven B. Segletes Apr 07 '16 at 18:47
  • Hello. How can I put an annotation without the line? Thanks. http://subefotos.com/ver/?c4842b6af2bfe83bbd078ab783c284f7o.png – Solid May 31 '17 at 20:52