我一直在研究 TikZ 人物模型,并能对其进行一定程度的改编。但要创建一个具有我想要的功能的人物模型则是另一回事。
对于我的论文,我希望创建这个图形
我知道这很简单,但我在调整方面遇到了困难
所以我一直在摆弄,结果还不错,但我想把绿色的框排成一行
这是我的 MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows}
\renewcommand{\figurename}{Figure}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture} [
title/.style={font=\fontsize{18}{18}\color{black!45}},
capt/.style={font=\fontsize{18}{18}\color{black!45},node distance=10em,anchor=west},
firm/.style={rectangle, draw, fill=blue!23, rounded corners, minimum width=6em,fill opacity=0.5},
industry/.style={rectangle, draw, fill=green!23, rounded corners, minimum width=25em,fill opacity=0.3},
region/.style={rectangle, draw, fill=red!23, rounded corners, minimum height=2em,fill opacity=0.3},
]
% Place nodes
\node (dummy) {};
\node [title] (in)[right=2cm of dummy] {India};
\node [title] [below=5mm of in] (infy) {Infosys};
\node [title] (wp) [below=1.5cm of in] {WiPro};
\node [firm] (InIt) [draw=black!50, fit= (infy) (wp)] {};
\node [title] (eur) [right=2cm of in] {Europa};
\node [title] (cap) [below=5mm of eur] {Cap};
\node [title] (Ts) [below=1.5cm of eur] {Tsystems};
\node [firm] (EuIt) [draw=black!50, fit= (cap) (Ts)] {};
\node [capt] (its) [below=1.25cm of dummy] {IT Services};
\node [capt] (ph) [below=3.5cm of dummy] {Pharmaceutical};
\node [industry][draw=black!50, fit=(its)(InIt)(EuIt)]{};
\node [title] (ran) [below=3cm of in] {Ranbaxy};
\node [title] (cip) [below=4cm of in] {Cipla};
%\node [draw=black!50, fit=(ph)(wp)(cap)]{};
\node [title] (nov) [below=3cm of eur] {Novartis};
\node [title] (gsk) [below=4cm of eur] {GSK};
\node [firm] (EuPh) [draw=black!50, fit= (nov) (gsk)] {};
\node [firm] (InPh) [draw=black!50, fit= (ran) (cip)] {};
\node [region] [draw=black!50, fit=(eur)(EuPh)]{};
\node [region] [draw=black!50, fit=(in)(InPh)]{};
\node [industry] [draw=black!50, fit=(ph)(InPh)(EuPh)]{};
\end{tikzpicture}
\caption{Clients graph}
\end{figure}
\end{document}
答案1
我将用\matrix
它来定位 Firm 节点,并手动绘制方框。(不知何故,该fit
库不起作用,因此无法使用最优雅的代码绘制方框:(
)。
代码
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,decorations,arrows,positioning,matrix,calc}
\usepackage{verbatim}
\begin{document}
\pagestyle{empty}
\begin{tikzpicture}[scale=2]
\tikzset{
mynode/.style={rectangle,rounded corners,draw=black, top color=white, bottom color=yellow!50,very thick, inner sep=1em, minimum size=3em, text centered},
myarrow/.style={->, >=latex', shorten >=1pt, thick},
mylabel/.style={text width=7em, text centered},
myFirm/.style={rectangle,rounded corners,draw=black, thin, inner sep=1em, minimum size=3em, text centered}
}
\matrix(m)[matrix of nodes,
nodes={myFirm},
row sep=5ex,
column sep=10ex,
]{
Novatis GSK & Cipla Ranbaxy \\
Cap T-sys & Infy WP \\
};
\pgfmathsetlengthmacro\thinpad{3pt}
\pgfmathsetlengthmacro\thickpad{6pt}
\draw let \p{11nw}=(m-1-1.north west), \p{11se}=(m-1-1.south east),
\p{21nw}=(m-2-1.north west), \p{21se}=(m-2-1.south east),
\p{12nw}=(m-1-2.north west), \p{12se}=(m-1-2.south east),
\p{22se}=(m-2-2.south east) in
($(\x{11nw},\y{11nw})+(-\thinpad,\thickpad)$)rectangle($(\x{11se},\y{21se})+(\thinpad,-\thickpad)$)
($(\x{12nw},\y{12nw})+(-\thinpad,\thickpad)$)rectangle($(\x{12se},\y{22se})+(\thinpad,-\thickpad)$)
($(\x{11nw},\y{11nw})+(-\thickpad,\thinpad)$)rectangle($(\x{12se},\y{12se})+(\thickpad,-\thinpad)$)
($(\x{11nw},\y{21nw})+(-\thickpad,\thinpad)$)rectangle($(\x{12se},\y{22se})+(\thickpad,-\thinpad)$)
;
\node[mynode,above=of m-1-1]{Europe};
\node[mynode,above=of m-1-2]{India};
\node[mynode,left =2.5 of m-1-1.center](Ph){Pharma};
\node[mynode,left =2.5 of m-2-1.center]{ITS};
\end{tikzpicture}
\end{document}
输出
更新
回应OP的更新。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc, shapes, arrows,backgrounds}
\renewcommand{\figurename}{Figure}
\begin{document}
\begin{figure}[!htb]
\centering
\begin{tikzpicture} [
title/.style={font=\fontsize{18}{18}\color{black!45},align=center,on grid},
capt/.style={font=\fontsize{18}{18}\color{black!45},node distance=10em,anchor=west},
firm/.style={rectangle, draw, fill=blue!23, rounded corners, minimum width=6em,minimum height=3em,fill opacity=0.5},
industry/.style={rectangle, draw, fill=green!23, rounded corners, minimum width=9cm,minimum height=1.5cm,on grid,fill opacity=0.3},
region/.style={rectangle, draw, fill=red!23, rounded corners, minimum height=2em,fill opacity=0.3},
]
% industry and region boxes
\node(IT)[industry]{};
\node(Ph)[industry,below=2cm of IT]{};
% place coordinates for later use
\coordinate(r1c1)at($(IT.west)!.2!(IT.east)$);
\coordinate(r1c2)at($(IT.west)!.5!(IT.east)$);
\coordinate(r1c3)at($(IT.west)!.85!(IT.east)$);
\coordinate(r2c1)at($(Ph.west)!.2!(Ph.east)$);
\coordinate(r2c2)at($(Ph.west)!.5!(Ph.east)$);
\coordinate(r2c3)at($(Ph.west)!.85!(Ph.east)$);
% firm boxes
\node(f1)[firm] at(r1c2){};
\node(f2)[firm] at(r2c2){};
\node(f3)[firm] at(r1c3){};
\node(f4)[firm] at(r2c3){};
% Place nodes
\node[title] at (r1c1){IT Services};
\node[title] at (r2c1){Pharmaceutical};
\node[title] at (r1c2){Infosys \\ WiPro};
\node[title] at (r2c2){Ranbaxy \\ Cipla};
\node[title] at (r1c3){Cap \\ Tsystems};
\node[title] at (r2c3){Novartis \\ GSK};
\node(IND)[title,yshift=1.2cm] at (r1c2) {India};
\node(EUR)[title,yshift=1.2cm] at (r1c3) {Europe};
% region boxes
\begin{scope}[on background layer]
\node[region,fit=(IND) (f2)]{};
\node[region,fit=(EUR) (f4)]{};
\end{scope}
\end{tikzpicture}
\caption{Clients graph}
\end{figure}
\end{document}