# protocol message diagram - arrow colored

\documentclass{article}
\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\usetikzlibrary{calc}
\begin{document}

\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\end{sequencediagram}

\end{document}


Is it possible assign a different color to pairs of arrows and put a legend with the colors for each protocol layer?

As pgf-umlsd uses a tikzpicture environment for sequence diagrams, you can simply set the TikZ key draw=<color> for the scope of the message in question:

\begin{scope}[draw=<color>]
\end{scope}


Or if you want to define a convenient macro, you can put this snippet in your preamble:

\usepackage{xargs}
\newcommandx\colmess[5][2=0]{%
\begin{scope}[draw=#1]%
\mess[#2]{#3}{#4}{#5}%
\end{scope}%
}


which gives you a new macro for messages with coloured arrows in the form \colmess{<color>}[<delay>]{<sender>}{<message content>}{<receiver>}.

Package pgf-umlsd does not allow to specify the color (nor any other option) of the "messages" (the arrows). However, you can enclose a message or a group of messages in a tikz scope and change the color inside the scope, for example:

\begin{scope}[draw=red]
\end{scope}


If you plan to use this construct several times, perhaps a better idea is to define your own \colormess to draw coloured messages, using the same trick:

\newcommand{\colormess}[4]{%
\begin{scope}[draw=#1]
\mess{#2}{#3}{#4}
\end{scope}
}


And then use it like this:

\colormess{red}{rnc}{Radio Link Setup Request}{nodeb}


Even a better option would be to create a \mymess based on the code of the original \mess, but accepting also any tikz style to be passed to the draw command:

\newcommand{\mymess}[5][0]{
\stepcounter{seqlevel}
\path
(#3)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess from) {};
\path
(#5)+(0,-\theseqlevel*\unitfactor-0.7*\unitfactor) node (mess to) {};
\draw[->,>=angle 60,#2] (mess from) -- (mess to) node[midway, above]
{#4};

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


Which can be used like:

\mymess{red, dashed, -latex}{rnc}{Radio Link Setup Request}{nodeb}

• Hi JLDiaz, the text above the arrow is possible to take the same color? for example \colormess{red}{rnc}{Radio Link Setup Request}{nodeb} the arrow red and the text "Radio Link Setup Request" red too – user21431 Mar 22 '13 at 8:16
• @user21431 That is the default behaviour, isn't? I tried with last command \mymess and worked as you ask. – JLDiaz Mar 22 '13 at 9:13
• I'm sorry, it's true jLDiaz, the behavior of the command mymess do what I indicated. I was checking the command scope, that was just for the arrows. Than you very much for the help! – user21431 Mar 22 '13 at 10:08