TikZ新手,绘制复杂图表

TikZ新手,绘制复杂图表

我正在尝试重新创建下图:

在此处输入图片描述 这是我的代码:

    \documentclass{article} 
    \usepackage{tikz}
    \usetikzlibrary{arrows,fit,shadows,calc,positioning}

    \begin{document}
            \begin{figure}[t]
        \centering      
        \begin{tikzpicture}[
        node distance=0.1cm,
        mynode/.style={
            draw,
            outer sep=0pt,
            text centered,
            text width= 2cm,
        },]
        \node[mynode,fill=red] (line1a) {container};    
        \node[mynode,fill=red] (line1b) [right=of line1a] {container};
            \node[mynode,fill=red] (line1c) [right=of line1b] {container};
        \node[mynode,fill=purple] (line2a)[fit = (line1a)(line1c),
        below = 1cm of line1a.west,
        anchor= south west, inner sep=0, label=center:{container Runtime}] {};
        \node[mynode,fill=cyan] (line3a)[fit = (line2a),
        below = 1cm of line2a.west,
        anchor= south west, inner sep=0, label=center:{Container OS}] {};   
        \node[mynode,fill=gray] (line4a)[fit = (line3a),
        below = 1cm of line3a.west,
        anchor= south west, inner sep=0, label=center:{Physical Host (or VM)}] {};      
        \end{tikzpicture}
        \caption{cap}
        \label{figure:cap}
    \end{figure}
    \end{document}

我目前的进展如下: 在此处输入图片描述

我对 TikZ 还不熟悉,有没有更简单的方法来绘制它?

答案1

像这样?

在此处输入图片描述

我留给你的正确的文字和颜色....

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
                calc,
                positioning
                }

\begin{document}
    \begin{tikzpicture}[
    node distance=2mm and 3mm,
    box/.style args = {#1/#2}{%
        minimum width=#1, minimum height=6mm, align=center,
        fill=#2,
        font=\bfseries, text=white,
        draw, inner sep=2mm, outer sep=0mm}
                        ]
% left containers (in vertical midddle of image)
\node (nLa) [box=20mm/red]                {container};
\node (nLb) [box=20mm/red,right=of nLa]   {container};
\node (nLc) [box=20mm/red,right=of nLb]   {container};
% right containers (in vertical midddle of image)
\node (nRa) [box=20mm/red,right=of nLc]   {container};
\node (nRb) [box=20mm/red,right=of nRa]   {container};
\node (nRc) [box=20mm/red,right=of nRb]   {container};
% nodes below (left and right column)
\path   let \p1 = ($(nLa.west) - (nLc.east)$),
            \n1 = {veclen(\y1,\x1)} in
        node (nL2)   [box=\n1/purple, below=of nLb] {container Runtime}
        node (nL3)   [box=\n1/cyan,   below=of nL2] {Container OS}
        node (nL4)   [box=\n1/cyan,   below=of nL3] {Physical Host (or VM)}
        %
        node (nR2)   [box=\n1/purple, below=of nRb] {container Runtime}
        node (nR3)   [box=\n1/cyan,   below=of nR2] {Container OS}
        node (nR4)   [box=\n1/cyan,   below=of nR3] {Physical Host (or VM)};
% nodes on bottom and top
\path   let \p1 = ($(nLa.west) - (nRc.east)$),
            \n1 = {veclen(\y1,\x1)} in
        node (nB)   [box=\n1/purple,
                     below=of $(nL4.south)!0.5!(nR4.south)$]        {DevOps Tools}
        %
        node (nT1)  [box=\n1/black,
                     above=8mm of $(nLc.north)!0.5!(nRa.north)$]    {Container Network}
        node (nT2)  [box=\n1/blue!40!black,above=of nT1]            {Container \dots}
        node (nT3)  [box=\n1/blue!80!black,above=of nT2]            {Container \dots}
        node (nT4)  [box=\n1/blue!50,above=of nT3]                  {Container \dots};            
% nodes on left and right
\path   let \p1 = ($(nT4.north west) - (nL4.south west)$),
            \n1 = {veclen(\y1,\x1)} in
        node (L1)   [box=\n1/purple!80!black,
                    left=of $(nT4.north west)!0.5!(nL4.south west)$,
                    anchor=south, rotate=90]                        {Configureation \dots}
        node (L2)   [box=\n1/olive,
                    left=of L1.north,
                    anchor=south, rotate=90]                        {Marketplace/Image Management}
        node (L2)   [box=\n1/gray,
                    right=of $(nT4.north east)!0.5!(nR4.south east)$,
                    anchor=north, rotate=90]                        {Security}
        ;
   \end{tikzpicture}
\end{document}

相关内容