我想得到这个tikz
。
这是我目前得到的
\documentclass[border=10pt]{standalone}
%\documentclass[border=10pt]{article}
\usepackage{tikz}
\usetikzlibrary {shapes.multipart}
\begin{document}
\begin{tikzpicture}
\tikzset{every node/.style={rectangle split, draw, minimum width = 0.5cm}}
\node[rectangle split part fill={green!50}] {};
\node[rectangle split part fill={yellow!50}]at (0.5, 0){};
\end{tikzpicture}
\end{document}
请提供任何提示。
答案1
经过一些手动调整...
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,
shapes.multipart}
\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\begin{document}
\begin{tikzpicture}[
node distance = 0pt,
VMPN/.style = {rectangle split,rectangle split parts=5,
draw,
fill=#1,
text width=4cm, align=center,
inner sep=0pt, outer sep=0pt}
]
\node (n1) [VMPN=green!30,
label=Urban] {\nodepart{one} \vphantom{$B_1^2$}
\nodepart{two} \vphantom{$B_1^2$}
\nodepart{three} ~\\ $\vdots$\\[-1ex]~
\nodepart{four} \vphantom{$B_1^2$}
\nodepart[inner ysep=0pt]{five}
\begin{tabularx}{\linewidth}{*{4}{>{$}C<{$}|}@{}}
H_1 & H_2 & \dots & H_{10}
\end{tabularx}
};
\node (n2) [VMPN=yellow!30,
right=of n1,
label=Rural] {\nodepart{one} \vphantom{$B_1^2$}
\nodepart{two} \vphantom{$B_1^2$}
\nodepart{three} ~\\ $\vdots$\\[-1ex]~
\nodepart{four} ~\vphantom{$B_1^2$}
\nodepart[inner ysep=0pt]{five}
\begin{tabularx}{\linewidth}{*{4}{>{$}C<{$}|}@{}}
H_1 & H_2 & \dots & H_{10}
\end{tabularx}
};
\node[left=of n1.one west] {$B_1$};
\node[left=of n1.two west] {$B_2$};
\node[left=2mm of n1.three west] {$\vdots^{}_{_~}$};
\node[left=of n1.four west] {$B_{19}$};
\node[left=of n1.five west] {$B_{20}$};
\node[right=of n2.one east] {$B_1$};
\node[right=of n2.two east] {$B_2$};
\node[right=2mm of n2.three east] {$\vdots^{}_{_~}$};
\node[right=of n2.four east] {$B_{49}$};
\node[right=of n2.five east] {$B_{50}$};
\end{tikzpicture}
\end{document}
编辑: 您可以通过两种方式更改节点标签(城市、乡村)的颜色:
- 与
label=\textcolor{red}{Urban}
上面的 MWE 一样,或者 - 和
label={[text=red]Urban}
答案2
根据您的要求 - 最后一行可以使用tikz/multipart
- 我没有输入所有数据
\documentclass{article}
%\usepackage{tikz,tikz-qtree}
%\usetikzlibrary{shapes,trees}
\usetikzlibrary {shapes.multipart,positioning}
\begin{document}
\begin{tikzpicture}
\tikzset{
rect1/.style={
rectangle split,
rectangle split parts=4,
draw,
minimum width=4cm,
% minimum height=1cm
},
rect2/.style={
rectangle,
% rectangle split parts=4,
% draw,
minimum width=1cm
}
}
\node[rect1,fill={yellow!30}] (r1) at (1.5,0) {};
\node[rect1, fill={green!30}] at (5.5,0) {};
\node[rect2, ] (r2) at (1.5,1) {d};
\node[rect2, ] at (5.5,1) {h};
\node[rect2,left=of r1.one split west,shift={(1cm,5pt)}] (r3) {1};
\node[rect2,left=of r1.two split west,shift={(1cm,5pt)}] {2};
\end{tikzpicture}
\end{document}