围绕 TikZ 图形的框

围绕 TikZ 图形的框

我有这个代码

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning}


\begin{document}

\begin{tikzpicture}[
  every node/.append style={minimum width = 3 cm, minimum height = 1 cm, fill=green},
  node distance=2mm
]
  \node(frontend) {Frontend};
  \node(nginx) [below=of frontend] {NGINX};
  \node(debian) [below=of nginx] {Debian};
  \node(backend) [right=of frontend] {Backend};
  \node(nodejs) [below=of backend] {NodeJS};
  \node(coreos) [below=of nodejs] {CoreOS};
  \node(database) [right=of backend] {Database};
  \node(postgresql) [below=of database] {PostgreSQL};
  \node(alpine) [below=of postgresql] {Alpine};
  \node(docker) [below=of coreos,minimum width = 9.4 cm] {Docker engine};
  \node(hostos) [below=of docker,minimum width = 9.4 cm] {Host Operating System};
  \node(physical-server) [below=of hostos,minimum width = 9.4 cm] {Physical server};

\end{document}

从而产生

在此处输入图片描述

我想要一个围绕三个小型垂直节点(例如 Frontend、NGINX、Debian)的框。并且希望有编程配色方案。

答案1

可能你想要的是下面这样的东西:

在此处输入图片描述

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, matrix}
\colorlet{mybasecolor}{green}
\begin{document}


\begin{tikzpicture}
 \matrix(table)[
  matrix of nodes,
  row sep =2mm,
  column sep = 2mm,
  nodes={minimum width = 3 cm, minimum height = 1 cm, fill=mybasecolor},
  column 2/.style={nodes={fill=mybasecolor!50}},
  column 3/.style={nodes={fill=mybasecolor!25}},
  ] 
  {Frontent & Backend & Database    \\
   NGINX    & NodeJS  & PostgreSQL  \\
   Debian   & CoreOS  & Alpine      \\
  };
  \node[draw, fill=none, inner sep=1mm,fit=(table-1-1.north west) (table-3-1.south east)] {};
  \tikzset{every node/.append style={minimum width = 9.4 cm, minimum height = 1 cm, fill=mybasecolor!75!black},
  node distance=2mm,}
  \node(docker) [below=of table] {Docker engine};
  \node(hostos) [below=of docker] {Host Operating System};
  \node(physical-server) [below=of hostos] {Physical server};
\end{tikzpicture}
\end{document}

相关内容