3

I am new to Latex and still trying to find my way around things. I am using the pgf-umlsd package to create a sequence diagram which traces out exchange of messages between functions. Due to space constraints, I need the width of the diagram to be as minimal as possible. Therefore, I am trying to rotate the label of the thread by about 30-45 degrees. Currently, this is what I could manage to come up with:

What I have This is not the ideal diagram I want, since sometimes, if the function name is too long, it overlaps with the labels on the messages. I am using \rotatebox to achieve this.

What I want to achieve is a diagram like this: (Please excuse my poor editing skills!) What I want

Essentially, I want to move the thread label so that it begins from the top of the thread and tilts upwards. How can I do this?

I am using pdflatex to generate a PDF rendering of the image. Here's the code I'm using:

\documentclass[tikz]{standalone}
\usepackage{graphics}
\usepackage{tikz}
\usepackage{pgf-umlsd}
\usepackage[T1]{fontenc}

\begin{document}
\begin{sequencediagram}
\tikzstyle{inststyle}=[]
\pgfumlsdunderlinefalse
\renewcommand{\newthread}[3][gray!30]{
  \newinst{#2}{\rotatebox[x=25pt,y=25pt]{30}{#3}}
  \stepcounter{threadnum}
  \node [below of=inst\theinstnum,node distance=0.8cm]
   (thread\thethreadnum) {};
  \tikzstyle{threadcolor\thethreadnum}=[fill=none]
  \tikzstyle{instcolor#2}=[fill=none]
 }
\newthread{function\string_name\string_one}
{function\string_name\string_one}{}
\newthread{function\string_name\string_two}
{function\string_name\string_two}{}
\newthread{function\string_name\string_three}
{function\string_name\string_three}{}
\newthread{function\string_name\string_four}
{function\string_name\string_four}{}
\newthread{function\string_name\string_five}
{function\string_name\string_five}{}
\newthread{function\string_name\string_six}
{function\string_name\string_six}{}

\mess{function\string_name\string_one}{}{function\string_name\string_two}
\mess{function\string_name\string_two}{}
{function\string_name\string_three}
\mess{function\string_name\string_three}{}
{function\string_name\string_four}
\mess{function\string_name\string_four}{}
{function\string_name\string_five}
\mess{function\string_name\string_five}{}
{function\string_name\string_six}

\end{sequencediagram}
\end{document}

I tried adding options to the \rotatebox command and changing the origin but it did not help.

7
  • Welcome! Note that \tikzstyle is deprecated.
    – cfr
    Commented Jul 27, 2017 at 1:28
  • Does this compile without error for you? Because it certainly won't compile for me!
    – cfr
    Commented Jul 27, 2017 at 2:49
  • Sorry about that! There was a missing ] in the \node command at the beginning. Its compiling now for me.
    – Achala Rao
    Commented Jul 27, 2017 at 14:04
  • I just used \tikzstyle to remove the box outline around the function names.
    – Achala Rao
    Commented Jul 27, 2017 at 14:07
  • \tikzset would be the recommended way now.
    – cfr
    Commented Jul 27, 2017 at 15:51

1 Answer 1

0

A suggestion where I redefine \newinst to add the thread names with labels instead of using the node directly.

output of code

\documentclass[tikz]{standalone}
\usepackage{pgf-umlsd}
\usepackage[T1]{fontenc}

\begin{document}
\begin{sequencediagram}
\tikzset{inststyle/.style={}}
\pgfumlsdunderlinefalse
\renewcommand{\newinst}[3][2]{
  \stepcounter{instnum}
  \path (inst\thepreinst.east)+(#1,0) node[inststyle,label={[anchor=west,rotate=45,xshift=-5pt]above:#3}] (inst\theinstnum)
  {};
  \path (inst\theinstnum)+(0,-0.5*\unitfactor) node (#2) {};
  \tikzstyle{instcolor#2}=[]
  \stepcounter{preinst}
}

\newthread{function\string_name\string_one}
{function\string_name\string_one}{}
\newthread{function\string_name\string_two}
{function\string_name\string_two}{}
\newthread{function\string_name\string_three}
{function\string_name\string_three}{}
\newthread{function\string_name\string_four}
{function\string_name\string_four}{}
\newthread{function\string_name\string_five}
{function\string_name\string_five}{}
\newthread{function\string_name\string_six}
{function\string_name\string_six}{}

\mess{function\string_name\string_one}{}{function\string_name\string_two}
\mess{function\string_name\string_two}{}
{function\string_name\string_three}
\mess{function\string_name\string_three}{}
{function\string_name\string_four}
\mess{function\string_name\string_four}{}
{function\string_name\string_five}
\mess{function\string_name\string_five}{}
{function\string_name\string_six}

\end{sequencediagram}
\end{document}
1
  • I just came across a similar solution a few days ago and implemented it. Thank you!
    – Achala Rao
    Commented Sep 1, 2017 at 21:56

You must log in to answer this question.

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