5

I am drawing a sequence diagram using Tikz. I first tried tikz-uml, but it has some issues which I asked about in another question.

I am now trying out pgf-umlsd, but it lacks the support for the dashed horizontal line which separates the alternatives in the alt block.

This is what I currently have:

\documentclass{article} \usepackage{pgf-umlsd} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{arrows} \usepackage{pgf-umlsd} \begin{document} \begin{sequencediagram} \newthread{t}{:Thread} \newinst[1]{i}{:Instance} \begin{sdblock}{alt}{[condition]} \begin{call}{t}{if\_true()}{i}{} \end{call} \begin{call}{t}{if\_false()}{i}{} \end{call} \end{sdblock} \end{sequencediagram} \end{document} 

original

I'd like to draw a dashed line between the two alternatives like this. How can I do that?

desired output

I already found a definition of \separateline, however the line is not starting/ending at the border of the alt block:

\documentclass{article} \usepackage{pgf-umlsd} \usepackage{tikz} \usepackage{pgfplots} \usetikzlibrary{arrows} \usepackage{pgf-umlsd} \begin{document} \newcommand{\separateline}[3][dotted, color=black, very thick]{ \stepcounter{seqlevel} \path (#2)+(.1,-\theseqlevel*\unitfactor-.8*\unitfactor) node (from) {} (#3)+(-.1,-\theseqlevel*\unitfactor-.8*\unitfactor) node (to) {}; \draw[#1] (from) -- (to); } \begin{sequencediagram} \newthread{t}{:Thread} \newinst[1]{i}{:Instance} \begin{sdblock}{alt}{[condition]} \begin{call}{t}{if\_true()}{i}{} \end{call} \separateline{t}{i} \begin{call}{t}{if\_false()}{i}{} \end{call} \end{sdblock} \end{sequencediagram} \end{document} 

enter image description here

1 Answer 1

4

If you look into pgf-umlsd.sty file, will see that the sdblock is drawn as a rectangle with corners on coordinates nw and se. And these coordinates will be redefined with every new sdblock.

Then my suggestion consists in drawing separation line right after every sdblock. And in case, you want some separation between inside block elements use \stepcounter.

The complete code could be:

\documentclass{article} \usepackage{pgf-umlsd} % Already loads TiKZ and libraries arrows and shadows \begin{document} \begin{sequencediagram} \newthread{t}{:Thread} \newinst[1]{i}{:Instance} \begin{sdblock}{alt}{[condition]} \begin{call}{t}{if\_true()}{i}{} \end{call} \stepcounter{seqlevel} %Vertical empty space between `calls` \begin{call}{t}{if\_false()}{i}{} \end{call} \end{sdblock} \path (nw)--coordinate (aux) (se); \draw[dashed] (nw|-aux)--(aux-|se); \end{sequencediagram} \end{document} 

enter image description here

2
  • any clever way to draw it in the place of the separator instead of the middle of block? Commented Apr 21, 2020 at 19:31
  • @majkrzak Sorry but I don't understand your question. May be you want to make a public question with reference to this one. This way you'll get more readers and probably better help. Commented Apr 22, 2020 at 6:43

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.