1

This is a MWE for a sequence diagram using pgf-umlsd: (taken from here)

\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}

enter image description here

How can each label be aligned in parallel to its corresponding arrow?

efie
  • 409
  • From looking at the code, I don't think it is possible out of the box. You'll need extra options given to the nodes on the paths, and \mess does not provide this. Have a look in pgf-umlsd.sty, you can easily make your own version of \mess it is a fairly simple macro. – daleif Jul 21 '17 at 14:13
  • And please don't use [H], learn to use floats properly, then there is no need for [H]. – daleif Jul 21 '17 at 14:14
  • 1
    Basically you'll need to add the sloped option to the midway node in the last \path in the \mess definition. – daleif Jul 21 '17 at 14:17
  • Thank's a lot, it works. Can you post your comments as an answer such that I can accept it? – efie Jul 21 '17 at 14:37

1 Answers1

2

Looking at the code for pgf-umlsd.sty we get that \mess is defined as

% message between threads
% Example:
% \mess[delay]{sender}{message content}{receiver}
\newcommand{\mess}[4][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};

  \node (#3 from) at (mess from) {};
  \node (#3 to) at (mess to) {};
}

The node with the midway option is the node we are looking for. As we can see \mess does not give any way of adding configurations to that node.

I'd just copy the code for \mess, call it \messS and in that code, just add sloped to the options for the midway node.

BTW: please don't use the [H] float placement. This is often a sign that you are not using floats in the proper manner.

daleif
  • 54,450