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.

  • Hi enigmator. A tip: if you copy and paste the url of other Q/A here, the title will be automatically displayed. – Claudio Fiandrino Apr 29 '14 at 12:37
  • 1
    @ClaudioFiandrino Ok great, thanks for the tip! – enigmator Apr 29 '14 at 12:38
  • 1
    Take a look at tex.stackexchange.com/a/155088/1952 – Ignasi Apr 29 '14 at 12:40
  • @Ignasi, it seems to work well, however I don't manage to add new lines inside nodes. – enigmator Apr 29 '14 at 14:20
  • @enigmator you must fix some text width in node options. You can combine it with align. Look at tex.stackexchange.com/a/24376/1952 – Ignasi Apr 29 '14 at 14:33
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 7 '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 7 '16 at 16:52
  • Thanks but I need braces (i.e. round brackets). How can I do this? – user2192774 Apr 7 '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 7 '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 7 '16 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.