3

I wanted to make a similar structure based on this example. But I'm currently stuck at this point:

  1. The top layers should be left and rigth aligned
  2. I think the code can be WAY better

Here is my MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz} 
    \usetikzlibrary{chains}
    \usetikzlibrary{positioning}
\definecolor{mycolor}{RGB}{8,108,131}

\begin{document} 
    \begin{tikzpicture}[
        scale=0.75,
        start chain=1 going below, 
        start chain=2 going right,
        node distance=1mm,
        desc/.style={
            scale=0.75,
            on chain=2,
            rectangle,
            rounded corners,
            draw=black, 
            very thick,
            text centered,
            text width=8cm,
            minimum height=12mm,
            fill=mycolor!30
            },
        1/.style={
            fill=mycolor!10
        },
        2/.style={
            fill=mycolor!30
        },
        3/.style={
            fill=mycolor!50
        },
        4/.style={
            fill=mycolor!70
        },
        5/.style={
            fill=mycolor!70
        },
        level/.style={
            scale=0.75,
            on chain=1,
            minimum height=12mm,
            text width=2cm,
            text centered
        },
        every node/.style={font=\sffamily}
    ]

    % Levels
    \node [level] (Level 5) {Layer 5};
    \node [level] (Level 4) {Layer 4};
    \node [level] (Level 3) {Layer 3};
    \node [level] (Level 2) {Layer 2};
    \node [level] (Level 1) {Layer 1};

    % Descriptions
    \chainin (Level 5); % Start right of Level 5
    \node [desc, 5] (5) {Applications layer};
    \node [ scale=0.75,
            rectangle,
            rounded corners,
            draw=black, 
            very thick,
            text centered,
            text width=8cm,
            minimum height=12mm,
            fill=mycolor!30,
           text width=3.5cm, xshift=2.25cm,above left= of 5] {TLS};
    \node [scale=0.75,
            rectangle,
            rounded corners,
            draw=black, 
            very thick,
            text centered,
            text width=8cm,
            minimum height=12mm,
            fill=mycolor!30,text width=3.5cm, xshift=-4.5cm,above right= of 5]  {TLS in HTTPS};

    \node [desc, 4, continue chain=going below] (4) {Transport layer};
    \node [desc,3] (3) {Network layer};
    \node [desc,2] (2) {Data link layer};
    \node [desc,1] (1) {Physical layer};
    \end{tikzpicture}
\end{document} 

Which give me:

output

Thanks for the help

4

enter image description here

and quite shortened code:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{tikz}
    \usetikzlibrary{chains,
                    positioning}
\definecolor{mycolor}{RGB}{8,108,131}

\begin{document}
    \begin{tikzpicture}[
node distance = 1mm and 0mm,
       start chain = going below,
  desc/.style args = {#1/#2}{
            rectangle, rounded corners, draw, very thick,
            fill=mycolor!#1,
            text width=8cm, align=center,
            minimum height=12mm,
            label=left:Layer #2,
            on chain
                            },
      level/.style = {
            rectangle, rounded corners, draw, very thick,
            fill=mycolor!30,
            text width=3cm, align=center,
            minimum height=12mm},
              font = \sffamily
                            ]
\node (n5) [desc=70/5]  {Applications layer};
    \node [level,above right=of n5.north west] {TLS};
    \node [level,above  left=of n5.north east] {TLS in HTTPS};
\node   [desc=70/4]     {Transport layer};
\node   [desc=50/3]     {Network layer};
\node   [desc=30/2]     {Data link layer};
\node   [desc=10/1]     {Physical layer};
    \end{tikzpicture}
\end{document}

note:

  • for positioning of top two nodes is used the positioning library. they are positioned above left from north west corner of node Application layer and above right from its north east corner
  • all other nodes with style desc are placed in the chain
  • style for desc has two parameters, first determine color of fill, second layer level which is written as label to node.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.