我试图得到这个数字:
该图由以下代码生成:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes,backgrounds,arrows}
\begin{document}
\begin{tikzpicture}
\tikzstyle{bigbox} = [minimum width=3.5cm, minimum height=4.2cm,draw, thick, rounded corners, rectangle]
\tikzstyle{bigbox2} = [minimum width=2cm, draw, thick, rounded corners, rectangle]
\tikzstyle{box} = [minimum width=2.7cm, rounded corners,rectangle]
\begin{scope}[every node/.style={minimum width=2cm,minimum height=1.5cm,draw,inner sep=0pt}]
\node [txtstyle] (n1) {};
\node [txtstyle,xshift=2cm] (n2) {};
\node [txtstyle,xshift= 4cm] (n3) {};
\end{scope}
\begin{scope}[every node/.style={text width=2cm,anchor=north west,text height=2.86cm,draw}]
\node [txtstyle,xshift=4.985cm,yshift=0.76cm] (n4) {};
\end{scope}
\begin{scope}[every node/.style={text width=5.77cm,anchor=north west,text height=0.3cm,text centered}]
\node [txtstyle,xshift=-1.01cm,yshift=-0.733cm,draw] (n5) {}; %
\node [txtstyle,xshift=-1.01cm,yshift=-1.27cm,draw] (n6) {}; %
\node [txtstyle,xshift=-1.01cm,yshift=-1.8cm,draw] (n7) {}; %
\node at (n5.north west){Query Compiler};
\node at (n6.north west){Query Optimizer};
\node at (n7.north west){Query Executor};
\end{scope}
\begin{scope}[every node/.style={text width=2cm,anchor=north west,text centered}]
\node at (n1.north west){Command \\ Line \\ Interface};
\node at (n2.north west){Web \\ Interface};
\node at (n3.north west){JDBC/ \\ ODBC \\ Server};
\node at (n4.north west){ ~\\ ~\\ ~\\ Meta \\ Data \\~ \\};
\end{scope}
\begin{pgfonlayer}{background}
\node[bigbox] [fit = (n1) (n4)] (box) {};
\end{pgfonlayer}
\node[box,above of=n1,xshift=0.5cm] (us) {Upper System Level};
%
%
%
\begin{scope}[every node/.style={minimum width=2cm,minimum height=0.5cm,rounded corners,inner sep=0pt}]
\node [txtstyle,below of=box,yshift=-2.5cm,draw] (h1) {Master};
\node [txtstyle,below left of=h1,yshift=-0.5cm,xshift=-2.3cm,draw] (h2) {Slave};
\node [txtstyle,below of=h1,yshift=-0.3cm] (h3) {...};
\node [txtstyle,below right of=h1,yshift=-0.5cm,xshift=2.3cm,draw] (h4) {Slave};
\node [txtstyle,above of=h2,yshift=0.3cm] (hd) {Hadooop};
\end{scope}
\begin{pgfonlayer}{background}
\node[bigbox2] [fit = (hd) (h4)] (box2) {};
\draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.200) to (h2.north);
\draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.340) to (h4.north);
\draw[
-triangle 90,
line width=1.5mm,
postaction={draw, line width=0.4cm, shorten >=0.2cm, -}
] (box.south) -- (box2.north);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
这是我在这个网站上找到的一堆代码的组合。它生成了我想要的内容,但它抱怨命令\tikzstyle
,表明它不知道它是什么并且会忽略它(但当我强制它完成编译时,它会生成我想要的内容)。代码看起来相当粗糙和不雅。为了更好地学习 tikz,我想问问这个论坛上的专家是否有更简洁的方法来实现我的愿望。
答案1
我设法找到了一种更优雅的解决方案,即使用分割矩形和对齐。这至少可以消除一些单个框放置时的麻烦。也许这很有用。
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{fit,shapes,backgrounds,arrows}
\begin{document}
\begin{tikzpicture}
\tikzstyle{bigbox} = [minimum width=3.5cm, minimum height=4.2cm,draw, thick, rounded corners, rectangle]
\tikzstyle{bigbox2} = [minimum width=2cm, draw, thick, rounded corners, rectangle]
\tikzstyle{box} = [minimum width=2.7cm, rounded corners,rectangle]
\tikzstyle{vbox} = [minimum width=2.7cm,rectangle,inner sep = -0.8pt]
\tikzset{txtstyle/.style={text=black}}
\node[align=center,draw,shape=rectangle split,
rectangle split horizontal,
rectangle split parts=3, text width=2cm,text centered] (A)
{Command \\ Line \\ Interface\nodepart{two}Web \\ Interface\nodepart{three}JDBC/ \\ ODBC \\ Server};
\node [align=center,draw,shape=rectangle split,
rectangle split parts=3, text width=6.5cm,text centered,anchor=north] (B) at (A.south)
{Query Compiler\nodepart{two}Query Optimizer\nodepart{three}Query Executor};
\node[vbox][fit=(A) (B)] (virtual) {};
\node[align=center,shape=rectangle,draw,text width=1.5cm,text height=0.68cm,anchor=west] (C) at (virtual.east) { ~\\ ~\\ Meta \\ Data \\~ \\~ \\};
\begin{pgfonlayer}{background}
\node[bigbox] [fit = (virtual) (C)] (box) {};
\end{pgfonlayer}
\node[box,above of=A,xshift=-1.5cm] (us) {Upper System Level};
\begin{scope}[every node/.style={minimum width=2cm,minimum height=0.5cm,rounded corners,inner sep=0pt}]
\node [txtstyle,below of=box,yshift=-2.5cm,draw] (h1) {Master};
\node [txtstyle,below left of=h1,yshift=-0.5cm,xshift=-2.3cm,draw] (h2) {Slave};
\node [txtstyle,below of=h1,yshift=-0.3cm] (h3) {...};
\node [txtstyle,below right of=h1,yshift=-0.5cm,xshift=2.3cm,draw] (h4) {Slave};
\node [txtstyle,above of=h2,yshift=0.3cm] (hd) {Hadooop};
\end{scope}
\begin{pgfonlayer}{background}
\node[bigbox2] [fit = (hd) (h4)] (box2) {};
\draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.200) to (h2.north);
\draw[<->,>=latex', shorten >=2pt, shorten <=2pt,thick] (h1.340) to (h4.north);
\draw[->,>=latex', shorten >=2pt, thick] (box.south) to (box2.north);
\draw[
-triangle 90,
line width=1.5mm,
postaction={draw, line width=0.4cm, shorten >=0.2cm, -}
] (box.south) -- (box2.north);
\end{pgfonlayer}
\end{tikzpicture}
\end{document}
答案2
错误消息是关于txtstyle
未定义,而不是关于\tikzstyle
。这需要在某处定义,因此您可以这样说:
\tikzset{txtstyle/.style={text=black}}
txtstyle
或者在使用时想要应用的每种风格。
您的代码使用\tikzstyle
,应\tikzset
按照应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?。