6

I am trying to achieve the chart as in the image attached.

RRC

I tried with this code but I have difficult to insert the texts.

Please suggest me if there is a more elegant way to achieve this.

Regards Leo

the code is:

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usepackage{inputenc}
\usetikzlibrary{arrows,automata,shadows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}

\tikzset{
    state/.style={
           rectangle,
           draw=black, 
           minimum height=2em,
           inner sep=2pt,
           text centered,
           drop shadow
           },
}

\begin{document}

    \begin{tikzpicture}[]

    \node[state,
       text width=3cm,
       fill=red!20,
       ] (RRC) 
    {
        \textbf{RRC}
    };


    \node[state,        
        yshift=-1.5cm,      
        right of=RRC, 
        node distance=3cm, 
        fill=yellow!20,
        anchor=center] (PDCP) 
    {
      \textbf{PDCP}
    };

    \node[state,        % layout (defined above)
        yshift=-0.5cm,  % move 2cm in y
        right of=PDCP,  % Position is to the right of RRC
        node distance=1.5cm,    % distance to QUERY
        fill=yellow!20,
    anchor=center] (BMC) 
    {
      \textbf{BMC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below of=RRC,
       xshift=2.5cm,
       yshift=-2.5cm,
       ] (RLC) 
    {
       \textbf{RLC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below of=RLC,
       yshift=-0.5cm,
       ] (MAC) 
    {
        \textbf{MAC}
    };

    \node[state,
       text width=8cm,
       below of=MAC,
       fill=green!20,
       yshift=-0.5cm,
       ] (PHY) 
    {
        \textbf{PHY}
    };

    \node[state,        % layout (defined above)
       xshift=7.2cm,        % move 2cm in y
       fill=red!20,
       anchor=center] (L3) 
    {
        \textbf{L3}
    };

    \node[state,        % layout (defined above)
      xshift=7.2cm,         % move x
      yshift=-3.25cm,
      minimum height=5.4cm,
      fill=blue!20,
      anchor=center] (L2) 
    {
        \textbf{L2}
    };

    \node[state,        % layout (defined above)
      xshift=7.2cm,         % move x
      yshift=-6.5cm,
      fill=green!20,
      anchor=center] (L1) 
    {
        \textbf{L1}
    };


    \draw [<->](RRC.west)-| ++(-0.6,-1)|-(PDCP.west);
    \draw [->](RRC.west)-| ++(-0.8,-1)|-(BMC.west);
    \draw [->](RRC.west)-| ++(-1.2,-1)|-(RLC.west);
    \draw [->](RRC.west)-| ++(-1.4,-1)|-(MAC.west);
    \draw [->](RRC.west)-| ++(-1.6,-1)|-(PHY.west);

    \draw (0,0.35) -- (0,1);
    \draw (0,-0.35) -- (0,-3.15);
    \draw (-0.5,-0.35) -- (-0.5,-3.15);
    \draw (0.5,-0.35) -- (0.5,-3.15);

    \draw(0,-3.85)--(0,-4.65);
    \draw(-0.5,-3.85)--(-0.5,-4.65);
    \draw(0.5,-3.85)--(0.5,-4.65);

    \draw(2.5,-5.35)--(2.5,-6.15);
    \draw(1.5,-5.35)--(1.5,-6.15);
    \draw(3.5,-5.35)--(3.5,-6.15);

    \draw(3,-1.15)--(3,1);
    \draw(3,-1.85)--(3,-3.15);

    \draw(4.5,-1.65)--(4.5,1);
    \draw(4.5,-2.35)--(4.5,-3.15);
    \draw(5.25,1)--(5.25,-3.15);
    \draw(6,1)--(6,-3.15);

    \draw(3,-3.85)--(3,-4.65);
    \draw(4.5,-3.85)--(4.5,-4.65);
    \draw(5.25,-3.85)--(5.25,-4.65);
    \draw(6,-3.85)--(6,-4.65);

    \end{tikzpicture}

\end{document}

3 Answers 3

5

See update for a better solution

You used a lot of "hardcoded" values to "manually" draw each line. I would have used named coordinates computed from the coordinates of the frame of each node to draw the connecctions instead.

Anyway, since you have this part already done, you can continue with the same approach for the remaining text. You can use your named nodes to position the text relative to them. For example, the text "Logical planes" is below the node you named RLC, so you can put it with:

\node[fill=white, below of=RLC, node distance=7mm, inner sep=0pt ] {Logical planes};

and so on.

Update

As promised, here are my recommendations for improving the code of this kind of figure, along with a complete re-implementation.

  1. First, don't abuse of xshift, yshift to position the nodes. Use instead the syntax of positioning library: right=1cm of other_node. For diagonal positioning it even accepts two parameters: below right=1cm and 3mm of other_node. This eliminates the need for shifting.

  2. Define named coordinates for simplifying the later drawing of lines. For example, a coordinate named "top" can be used to set the y-coordinate of the origin for all the vertical lines. This way, if you want to make all those lines a bit longer, you only have to change the definition of that coordinate. Also, use calc to define coordinates relative to other nodes or their anchor points. For example, the origin of the tree lines which start at the bottom of RRC can be expressed in relation to RRC.south, using calc expressions such as ($(RRC.south)+(0.5,0)$).

  3. Take advantage of the syntax (A|-B) to specify a coordinate which is in the vertical of node A, and in the horizontal of node B (one could say that the coordinate has x=x of A, y=y of B). Analogously it is also possible to use (A-|B) for the coordinate at the horizontal of A and vertical of B. Using this kind of syntax along with the named coordinates suggested in 2 allows for drawing all the lines without specifying hardcoded coordinates.

  4. Use a background layer to reduce the amount of lines to draw and auxiliar points to define. For example, instead of drawing three lines from RRC to RLC, and then another three "continuing" lines from RLC to MAC, it is easier to directly draw three lines from RRC to MAC, which pass "behind" RLC.

  5. To put labels on top of the lines, use nodes with fill=white and small inner sep.

Putting all these suggestions together:

\documentclass{article}
\usepackage{tikz}
\usepackage{inputenc}
\usetikzlibrary{arrows,automata,shadows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usetikzlibrary{decorations.pathreplacing} % For the braces

\tikzset{
    state/.style={
           rectangle,
           draw=black, 
           minimum height=2em,
           inner sep=2pt,
           text centered,
           drop shadow
           },
   line label/.style = {
       fill=white,
       inner sep=2pt,
       font=\small\sffamily
   },
   my brace/.style = {
       decorate,
       decoration={brace, amplitude=2mm},
       shorten >= -2pt,
       shorten <= -2pt,
   }
}

\pgfdeclarelayer{bg}    % declare background layer
\pgfsetlayers{bg,main}  % set the order of the layers (main is the standard layer)

\begin{document}

    \begin{tikzpicture}[node distance=8mm] % 8mm is the distance unless specified otherwise

    \node[state,
       text width=3cm,
       fill=red!20,
       ] (RRC) 
    {
        \textbf{RRC}
    };

    \node[state,        
        below right=1.3cm and 1cm of RRC,
        fill=yellow!20
        ] (PDCP) 
    {
      \textbf{PDCP}
    };

    \node[state,        % layout (defined above)
        below right=-2mm and 3mm of PDCP,
        fill=yellow!20,
        ] (BMC) 
    {
      \textbf{BMC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below=3.5cm of RRC.west, anchor=west,
       ] (RLC) 
    {
       \textbf{RLC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below=of RLC,
       ] (MAC) 
    {
        \textbf{MAC}
    };

    \node[state,
       text width=8cm,
       below=of MAC,
       fill=green!20,
       ] (PHY) 
    {
        \textbf{PHY}
    };

    \node[state,        % layout (defined above)
      fill=green!20,
      right=3mm of PHY,
      ] (L1) 
    {
        \textbf{L1}
    };

    \node[state,        % layout (defined above)
      minimum height=5.4cm,
      fill=blue!20,
      above=2mm of L1,
      ] (L2) 
    {
        \textbf{L2}
    };

    \node[state,        % layout (defined above)
       fill=red!20,
       above=2mm of L2,
       ] (L3) 
    {
        \textbf{L3}
    };

    % Some named coordinates to simplify the drawing of lines

    % Top of the figure. Only Y coordinate matters
    \coordinate[above=5mm of RRC] (top);

    % Three points at bottom of RRC
    \coordinate (RRC a) at ($(RRC.south)+(-0.8,0)$);
    \coordinate (RRC b) at (RRC.south);
    \coordinate (RRC c) at ($(RRC.south)+(0.8,0)$);

    % Three points at bottom of MAC
    \coordinate (MAC a) at ($(MAC.south)+(-0.8,0)$);
    \coordinate (MAC b) at (MAC.south);
    \coordinate (MAC c) at ($(MAC.south)+(0.8,0)$);

    % Two points at upper right of MAC
    \coordinate (MAC d) at ($(MAC.north east)+(-0.5,0)$);
    \coordinate (MAC e) at ($(MAC.north east)+(-1.3,0)$);

    % Now draw all lines, on background layer
    \begin{pgfonlayer}{bg}
        % Vertical lines from "top" to each box
        \draw (RRC.north|-top) -- (RRC.north);
        \draw (PDCP|-top) -- (PDCP|-MAC.north);
        \draw (BMC|-top) -- (BMC|-MAC.north);
        \draw (MAC d|-top) -- (MAC d);
        \draw (MAC e|-top) -- (MAC e);

        % Vertical lines from RRC to MAC
        \draw (RRC a) -- (RRC a|-MAC.north);
        \draw (RRC b) -- (RRC b|-MAC.north);
        \draw (RRC c) -- (RRC c|-MAC.north);

        % Vertical lines from MAC to PHY
        \draw (MAC a) -- (MAC a|-PHY.north);
        \draw (MAC b) -- (MAC b|-PHY.north);
        \draw (MAC c) -- (MAC c|-PHY.north);

        % Remaining lines with arrows
        \draw [<->](RRC.west)-| ++(-0.6,-1)|-(PDCP.west);
        \draw [->](RRC.west)-| ++(-0.8,-1)|-(BMC.west);
        \draw [->](RRC.west)-| ++(-1.2,-1)|-(RLC.west) node[pos=0.3,rotate=90,line label] {Control};
        \draw [->](RRC.west)-| ++(-1.4,-1)|-(MAC.west);
        \draw [->](RRC.west)-| ++(-1.6,-1)|-(PHY.west);
    \end{pgfonlayer}

    % Label lines
    \node[below=2mm of RRC,line label] {Signaling};
    \node[below=6mm of RRC,line label] {radio bearers};
    \node[above=1cm of BMC,line label] {U-Plane radio bearers};
    \node[below=2mm of RLC,line label] {Logical channels};
    \node[below=2mm of MAC,line label] {Transport channels};

    % Put "top" a bit higher, to draw the braces
    \coordinate[above=2mm of top] (top);
    % Braces
    \draw[my brace] (RRC.west|-top) -- (RRC.east|-top)
       node[midway,above=2mm,line label] {Control-plane};
    \draw[my brace] (PDCP|-top) -- (MAC d|-top)
       node[midway,above=2mm,line label] {User-plane};

    \end{tikzpicture}
\end{document}

Which produces:

Result

3
5

Another try with TikZ using my libraries positioning-plus and paths.ortho ([1], [2])

I am also using the shift left and shift right styles from the tikz-cd according to another answer of mine. Their implementation however is a little flawed as they do not work well with |*.

Maybe a decoration as in [3] and [4] might be better suited here.

Code

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{positioning-plus,paths.ortho,decorations.pathreplacing}
\tikzset{
  shift left/.style ={/tikz/commutative diagrams/shift left={#1}},
  shift right/.style={/tikz/commutative diagrams/shift right={#1}}}
\begin{document}
\begin{tikzpicture}[
 boxes/.style={draw, fill={colL#1}, text={colT#1}, font=\strut, text depth=+0pt},
 wide box/.style  ={boxes={#1}, minimum width=+6cm},
 normal box/.style={boxes={#1}, minimum width=+2cm},
 thin box/.style  ={boxes={#1}, minimum width=+1cm},
 box/.style={inner sep=+2pt, font=\footnotesize\sffamily},
 bol/.style={box, fill=white},
 label distance=+.1cm, pin distance=+.3cm,
 every pin edge/.style={draw},
 brace box/.style={box, above=\pgfdecorationsegmentamplitude},
 brace/.style={decorate, decoration={name=brace,amplitude=.1cm}}
 ]

\colorlet{colL1}{gray!50}  \colorlet{colT1}{black}
\colorlet{colL2}{gray}     \colorlet{colT2}{black}
\colorlet{colL3}{black!75} \colorlet{colT3}{white}

\node[wide box=1]               (phy) {PHY};
\node[wide box=2, above=of phy] (mac) {MAC};

  \path (phy) \foreach \i in {-1,...,1} {[shift left=.75cm*\i]edge (mac)};
  \path (phy) -- node[bol] {Transport channels} (mac);

\node[normal box=3, west above=4:of mac] (rrc) {RRC};

  \path (rrc) \foreach \i in {-1,...,1} {[shift left=.5cm*\i] edge (rrc|-mac.north)};
  \node also[label={[bol,align=center,name=srb]below:Signalling\\radio bearers},
             pin={[coordinate,name=cp']above:}] (rrc);
  \draw[brace, Y/.style={yshift=.2cm}] ([Y]rrc.west|-cp')
    -- node[brace box] {Control-plane} ([Y]rrc.east|-cp');

\node[thin box=2, above=2.5:of mac] (pdcp) {PDCP};
\node[thin box=2, below right=-.15 and .1:of pdcp] (bmc) {BMC};

  \path[|*] (pdcp) edge (mac) edge coordinate[at end] (pdcp') (cp')
            (bmc)  edge (mac) edge (cp');
  \path[*|] (cp') edge ([xshift*=-1] mac.north east)
                  edge coordinate[at start] (cp'') ([xshift*=-.4] mac.north east);

\node[wide box=2, above=of mac] (rlc) {RLC};
  \path (mac) -- node[bol] {Logical channels} (rlc);

\draw[brace, Y/.style={yshift=.2cm}]   ([Y]pdcp')
  -- node[brace box] (up) {User-place} ([Y] cp'');
\node[bol] at (srb-|up) {U-place radio bearers};

\path[lr, rounded corners] (rrc)
  \foreach [count=\i] \g/\t in {pdcp/?, bmc/?, rlc/Control, mac/?, phy/?}{
   edge[udlr/lr distance=\i*.2cm]
     node[style/.expanded={\if\t?coordinate\fi}, rotate=90, bol] {\t} (\g)};

\tikzset{node distance=+.5cm}
\node[right=of |(phy),       boxes=1]              (l1) {L1};
\node[right=of |(mac)(pdcp), boxes=2]              (l2) {L2};
\node[span vertical=(rrc),   boxes=3] at (l2|-rrc) (l3) {L3};
\end{tikzpicture}
\end{document}

Output

enter image description here

4
  • Hi, how can I install your libraries positioning-plus and paths.ortho ?
    – user21431
    Dec 19, 2013 at 8:57
  • 1
    @user21431 Download the files as linked in the answer and place them in your local texmf tree (see Where do I place my own .sty files, to make them available to all my .tex files?) If you just want to test them, you can place the files in the same folder as your main .tex file. Dec 19, 2013 at 17:13
  • Hi, I have put the files in the texmf directory tree as you suggested. when I compile in pdfLatex, the system return these errors: ! Package pgfkeys Error: I do not know the key '/tikz/commutative diagrams/shif t left' ! Use of \tikz@fig@scan@at doesn't match its definition. ! Package pgf Error: No shape named cp' is known. ecc.
    – user21431
    Dec 20, 2013 at 10:46
  • @user21431 Have you loaded the tikz-cd package as in my code? Dec 20, 2013 at 15:04
3

One option is to place the labels upon the figure outside of tikz. Here, I use \stackinset to accomplish it. I place the tikz image in an \sbox, and the nest a bunch of \stackinsets around the box. The only quirk was that to place the "Control Plane" and "User Plane" labels, I had to smash them, or else they changed the size of the resulting figure bounding box, which messed up the proper nesting of the \stackinsets.

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usepackage{inputenc}
\usetikzlibrary{arrows,automata,shadows}
\usetikzlibrary{positioning}
\usetikzlibrary{calc}
\usepackage{stackengine}
\newcommand\whitebox[1]{\fboxsep=1.5pt\relax\colorbox{white}{\textsf{#1}}}

\tikzset{
    state/.style={
           rectangle,
           draw=black, 
           minimum height=2em,
           inner sep=2pt,
           text centered,
           drop shadow
           },
}

\newsavebox\mytikz
\begin{document}

\sbox{\mytikz}{%
    \begin{tikzpicture}[]

    \node[state,
       text width=3cm,
       fill=red!20,
       ] (RRC) 
    {
        \textbf{RRC}
    };


    \node[state,        
        yshift=-1.5cm,      
        right of=RRC, 
        node distance=3cm, 
        fill=yellow!20,
        anchor=center] (PDCP) 
    {
      \textbf{PDCP}
    };

    \node[state,        % layout (defined above)
        yshift=-0.5cm,  % move 2cm in y
        right of=PDCP,  % Position is to the right of RRC
        node distance=1.5cm,    % distance to QUERY
        fill=yellow!20,
    anchor=center] (BMC) 
    {
      \textbf{BMC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below of=RRC,
       xshift=2.5cm,
       yshift=-2.5cm,
       ] (RLC) 
    {
       \textbf{RLC}
    };

    \node[state,
       text width=8cm,
       fill=blue!20,
       below of=RLC,
       yshift=-0.5cm,
       ] (MAC) 
    {
        \textbf{MAC}
    };

    \node[state,
       text width=8cm,
       below of=MAC,
       fill=green!20,
       yshift=-0.5cm,
       ] (PHY) 
    {
        \textbf{PHY}
    };

    \node[state,        % layout (defined above)
       xshift=7.2cm,        % move 2cm in y
       fill=red!20,
       anchor=center] (L3) 
    {
        \textbf{L3}
    };

    \node[state,        % layout (defined above)
      xshift=7.2cm,         % move x
      yshift=-3.25cm,
      minimum height=5.4cm,
      fill=blue!20,
      anchor=center] (L2) 
    {
        \textbf{L2}
    };

    \node[state,        % layout (defined above)
      xshift=7.2cm,         % move x
      yshift=-6.5cm,
      fill=green!20,
      anchor=center] (L1) 
    {
        \textbf{L1}
    };


    \draw [<->](RRC.west)-| ++(-0.6,-1)|-(PDCP.west);
    \draw [->](RRC.west)-| ++(-0.8,-1)|-(BMC.west);
    \draw [->](RRC.west)-| ++(-1.2,-1)|-(RLC.west);
    \draw [->](RRC.west)-| ++(-1.4,-1)|-(MAC.west);
    \draw [->](RRC.west)-| ++(-1.6,-1)|-(PHY.west);

    \draw (0,0.35) -- (0,1);
    \draw (0,-0.35) -- (0,-3.15);
    \draw (-0.5,-0.35) -- (-0.5,-3.15);
    \draw (0.5,-0.35) -- (0.5,-3.15);

    \draw(0,-3.85)--(0,-4.65);
    \draw(-0.5,-3.85)--(-0.5,-4.65);
    \draw(0.5,-3.85)--(0.5,-4.65);

    \draw(2.5,-5.35)--(2.5,-6.15);
    \draw(1.5,-5.35)--(1.5,-6.15);
    \draw(3.5,-5.35)--(3.5,-6.15);

    \draw(3,-1.15)--(3,1);
    \draw(3,-1.85)--(3,-3.15);

    \draw(4.5,-1.65)--(4.5,1);
    \draw(4.5,-2.35)--(4.5,-3.15);
    \draw(5.25,1)--(5.25,-3.15);
    \draw(6,1)--(6,-3.15);

    \draw(3,-3.85)--(3,-4.65);
    \draw(4.5,-3.85)--(4.5,-4.65);
    \draw(5.25,-3.85)--(5.25,-4.65);
    \draw(6,-3.85)--(6,-4.65);

    \end{tikzpicture}
}
\stackinset{c}{-2.2cm}{t}{0cm}{\smash{\whitebox{\parbox{3.5cm}{\centering%
  Control-plane\\$\overbrace{\rule{3cm}{0cm}}$}}}}{%
\stackinset{c}{2.25cm}{t}{0cm}{\smash{\whitebox{\parbox{3.5cm}{\centering%
  User-plane\\$\overbrace{\rule{3cm}{0cm}}$}}}}{%
\stackinset{c}{-2.2cm}{c}{2.2cm}{\whitebox{Signalling radio bearers}}{%
\stackinset{c}{2.25cm}{c}{2.2cm}{\whitebox{U-Plane radio bearers}}{%
\stackinset{c}{}{c}{-2.8cm}{\whitebox{Transport channels}}{%
\stackinset{c}{}{c}{-1.3cm}{\whitebox{Logical channels}}{%
\stackinset{c}{-5cm}{c}{1.3cm}{\rotatebox{90}{\whitebox{Control}}}{%
~\\~\\\usebox{\mytikz}%
}}}}}}}
\end{document}

enter image description here

You must log in to answer this question.

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