9

I want to make following Software architecture inside TikZ:

enter image description here

See below my code:

\documentclass[border=2px]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzset{
    green/.style  = {draw, rectangle, minimum width=1cm, minimum height=1cm, text centered, text width=1.2cm, font=\footnotesize, draw=black, fill=green!30},
    blue/.style   = {draw, rectangle, minimum width=6cm, minimum height=1cm, text centered, text width=5.0cm, font=\footnotesize, draw=black, fill=blue!30},
    yellow/.style = {draw, rectangle, minimum width=6cm, minimum height=1cm, text centered, text width=5.0cm, font=\footnotesize, draw=black, fill=yellow!30},
}

\begin{document}
\begin{tikzpicture}[node distance=1.1cm]
    \node (r1c1) [green] {VC++};
    \node (r1c2) [green, right of=r1c1, xshift=0.5cm] {VB.NET};
    \node (r1c3) [green, right of=r1c2, xshift=0.5cm] {C\#.NET};
    \node (r1c4) [green, right of=r1c3, xshift=0.5cm] {Others};
    \node (r2c1) [blue,  below of=r1c2, xshift=0.8cm] {COM-API Interface};
    \node (r3c1) [yellow, below of=r2c1] {Autodesk Inventor Application};

    \draw (r1c1);
    \draw (r1c2);
    \draw (r1c3);
    \draw (r1c4);
    \draw (r2c1);
    \draw (r3c1);
\end{tikzpicture}
\end{document}

Below is the generated diagram:

enter image description here

The modules inside generated diagram are not properly aligned. Any suggestions please?

2
  • You may be interested by the tcolorbox package.
    – DRi
    Jan 27, 2017 at 13:44
  • @DRi: Is it possible to get these types of figures using tcolorbox? How?
    – ravi
    Jan 27, 2017 at 14:30

3 Answers 3

11

Just for fun and as somebody proposed tcolorbox ...

\documentclass{article}

\usepackage[most]{tcolorbox}

\tcbset{enhanced, fontupper=\bfseries, notitle, sharp corners, halign=center, valign=center}

\begin{document}
\begin{tcbitemize}[%
    raster equal height=rows, 
    raster columns=4,
    raster equal height,
    raster every box/.style={height=2cm},
    raster column skip=1mm,
    raster row skip=1mm,
    colback=green!70!black]
\tcbitem VC++
\tcbitem VB.NET
\tcbitem C\#.NET
\tcbitem Others
\tcbitem[colback=blue!40, raster multicolumn=4]
COM-API Interface
\tcbitem[colback=yellow!50, raster multicolumn=4]
Autodesk Inventor Application
\end{tcbitemize}
\end{document}

enter image description here

3
  • This creates formatted text, not an image.
    – mike
    Sep 10, 2018 at 13:19
  • @mike And where is the problem? The result is like the desired "image".
    – Ignasi
    Sep 10, 2018 at 13:26
  • It was just neutral information. Depending on the use case there may (or may not) be a problem (e.g. no right click and save image).
    – mike
    Sep 10, 2018 at 13:36
10

Another solution using chain :

\documentclass[border=2px]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows, chains, calc}

\tikzset{
    green/.style  = {draw, rectangle, minimum width=2cm, minimum height=1cm, text centered, text width=1.2cm, font=\footnotesize, draw=black, fill=green!30},
    blue/.style   = {draw, rectangle, minimum width=8cm+3\pgflinewidth, minimum height=1cm, text centered, text width=5.0cm, font=\footnotesize, draw=black, fill=blue!30},
    yellow/.style = {draw, rectangle, minimum width=8cm+3\pgflinewidth, minimum height=1cm, text centered, text width=5.0cm, font=\footnotesize, draw=black, fill=yellow!30},
}

\begin{document}
\begin{tikzpicture}[start chain=1 going right,
  start chain=2 going below, node distance=1mm]
  \node [name=r1c1, on chain=1, green] {VC++};
  \node [name=r1c2, on chain=1, green] {VB.NET};
  \node [name=r1c3, on chain=1, green] {C\#.NET};
  \node [name=r1c4, on chain=1, green] {Others};
  \draw let \p1=($(r1c4.east)-(r1c1.west)$), \n1 = {veclen(\x1,\y1)} in
  node [name=r2c1, on chain=2, blue, anchor=north west, yshift=-1mm,
  minimum width=\n1-\pgflinewidth]
  at (r1c1.south west) {COM-API Interface};
  \draw let \p1=($(r1c4.east)-(r1c1.west)$), \n1 = {veclen(\x1,\y1)} in
  node [name=r3c1, on chain=2, yellow, minimum width=\n1-\pgflinewidth] {Autodesk Inventor Application};

\end{tikzpicture}
\end{document}

enter image description here

4
  • This is interesting.. however I couldn't understand it completely. Can you please add some explanation along with the answer?
    – ravi
    Jan 27, 2017 at 14:34
  • 1
    You should add a \strut to the text of each green node to get the text aligned horizontally. Jan 27, 2017 at 14:38
  • 1
    @RaviJoshi chain are explained in tikz documentation : section 46 and \letin section 14.15 ; I use let to calculate the right width of the 4 box
    – flav
    Jan 27, 2017 at 14:42
  • What should I do if I want to add one evenly split box below Autodesk, e.g. Desktop client and Web client? Adding to chain 1/2 does not bring the desired result. I think each row should have its own chain.
    – mike
    Sep 10, 2018 at 12:50
4

My solution in TikZ: use given coordinates, as you have more control with them. To use my coordinates, I had to adapt the minimal width of the middle and bottom layer boxes to be 8 cm.

EDIT

As requested in the comment, there should be a horizontal gap between the boxes.

Therefore I added option outer sep=1mm to the style definition. The outer sep works on the left and the right size of the box. Thus, the alignment of the first and last box will be ruined. I corrected that by adding some space to the x-coordinate of the first and last box accordingly. Please have a look at the comments in my MWE.

Here you are:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows}

\tikzset{
    green/.style  = {draw, rectangle, 
      minimum width=1.6cm, minimum height=1cm, 
      %% NEW: added outer space
      outer sep=1mm,
      %% continued as before
      text centered, text width=1.2cm, font=\footnotesize,
      draw=black, fill=green!30}, 
    blue/.style   = {draw, rectangle,
      minimum width=8cm, minimum height=1cm,
      text centered, text width=5.0cm, font=\footnotesize,
      draw=black, fill=blue!30}, 
    yellow/.style = {draw, rectangle, 
      minimum width=8cm, minimum height=1cm, 
      text centered, text width=5.0cm, font=\footnotesize,
      draw=black, fill=yellow!30}, 
}

\begin{document}
\begin{tikzpicture}
  %% Define the nodes of the rectangles in the top layer.
  %% Corrected the x-position of the VC++ and Other box.
  \node at (-0.2,3) [green] {VC++} ;
  \node at (2,3) [green] {VB.net} ;
  \node at (4,3) [green] {C\#} ;
  \node at (6.2,3) [green] {Others} ;
  %% Node of the second/middle layer
  \node at (3,2) [blue]  {COM-API Interface} ;
  %% Node of the bottom layer
  \node at (3,1) [yellow] {Autodesk Inventor Applikation} ;
\end{tikzpicture}
\end{document}

And the (also edited) result:

enter image description here

2
  • How to add space between each module ?
    – ravi
    Jan 27, 2017 at 14:32
  • I edited my MWE and the result. Hope you find it usefull.
    – Jan
    Jan 27, 2017 at 14:50

You must log in to answer this question.

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