\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning}
\usetikzlibrary{fit,positioning,arrows,automata}
\usepackage{amsmath}
\usepackage{fullpage}
\usepackage{graphicx}
\begin{document}
\begin{tikzpicture}
\tikzstyle{block}=[draw, fill=white,fill=blue!20, rectangle,minimum width={width("Magnetometer")+2pt},font=\small]
\tikzstyle{block3}=[draw, fill=white,fill=blue!20, rectangle, minimum width={width("Magnetometer")+2pt}, minimum height={height("Taxes")+18pt},font=\small],
\tikzstyle{basic}=[draw, text centered]
\tikzstyle{main}=[circle, minimum size = 2pt, thick, draw =black!80, node distance = 5mm]
\tikzstyle{connect}=[-latex, thick]
\tikzstyle{box2}=[rectangle, draw=black!100,minimum height=0.5cm, rectangle split, rectangle split horizontal =false, rectangle split parts=2, font =\small]
\tikzstyle{blockX}=[draw, draw=white, fill=white!100, rectangle, font=\small]
% 4 Treatments and double-sized Control
\node[block](SFBN){$S+F+B+N$};
\node[block,above=0.4cm of SFBN](SFB){$S+F+B$};
\node[block,above=0.4cm of SFB](SF){$S+F$};
\node[block,above=0.4cm of SF](Savings){$S$};
\node[block3,above=0.4cm of Savings](Control){Control};
% Measurements on Controls
\node [box2, right = 0.4cm of Control, draw=white!100] (Data1) {30 \nodepart{two} 600};
\node[main, fill = black!100] (B0) [right=of Data1] {};
\node[main, fill = black!100] (L1) [right=of B0] {};
\node[main, fill = black!100] (L2) [right=of L1] {};
\node[main, fill = black!100] (L3) [right=of L2] {};
\node[main, fill = black!100] (L4) [right=of L3] {};
\node[main, fill = black!100] (L5) [right=of L4] {};
\node[main,fill = black!100] (L6) [right=of L5] {};
\node[main,fill = black!100] (L7) [right=of L6] {};
% Measurments on Savings Treatment
\node [box2, draw=white!100, right = 0.01cm of Savings, below of =Data1] (Data2) {30 \nodepart{two}600};
\node[main,fill=black!100] (O0) [right=of Data2, below= of B0] {};
\node[main,fill=black!100] (O1) [right=of B0,below=of L1] {};
\node[main,fill=black!100] (O2) [right=of O1,below=of L2] {};
\node[main,fill=black!100] (O3) [right=of O2,below=of L3] {};
\node[main,fill=black!100] (O4) [right=of O3,below=of L4] {};
\node[main,fill=black!100] (O5) [right=of O4,below=of L5] {};
\node[main,fill=black!100] (O6) [right=of O5,below=of L6] {};
\node[main,fill=black!100] (O7) [right=of O6,below=of L7] {};
%Measurements on SF Treatment
\node [box2, draw=white!100, right = 0.01cm of SF, below of = Data2] (Data3) {30\nodepart{two}600};
\node[main,fill=black!100] (W0) [right=of SF,below=of O0] {};
\node[main,fill=black!100] (W1) [right=of W0,below=of O1] {};
\node[main,fill=black!100] (W2) [right=of W1,below=of O2] {};
\node[main,fill=black!100] (W3) [right=of W2,below=of O3] {};
\node[main,fill=black!100] (W4) [right=of W3,below=of O4] {};
\node[main,fill=black!100] (W5) [right=of W4,below=of O5] {};
\node[main,fill=black!100] (W6) [right=of W5,below=of O6] {};
\node[main,fill=black!100] (W7) [right=of W6,below=of O7] {};
%Measurements on SFB Treatment
\node [box2, draw=white!100, right = 0.01cm of SFB, below of = Data3] (Data4) {30\nodepart{two}600};
\node[main,fill=black!100] (Z0) [right=of SFB,below=of W0] {};
\node[main,fill=black!100] (Z1) [right=of Z0,below=of W1] {};
\node[main,fill=black!100] (Z2) [right=of Z1,below=of W2] {};
\node[main,fill=black!100] (Z3) [right=of Z2,below=of W3] {};
\node[main,fill=black!100] (Z4) [right=of Z3,below=of W4] {};
\node[main,fill=black!100] (Z5) [right=of Z4,below=of W5] {};
\node[main,fill=black!100] (Z6) [right=of Z5,below=of W6] {};
\node[main,fill=black!100] (Z7) [right=of Z6,below=of W7] {};
% Measurements on SFBN Treatment
\node [box2, draw=white!100, right= 0.01 of SFBN, below of = Data4] (Data5) {30 \nodepart{two}600};
\node[main,fill=black!100] (G0) [right=of SFBN,below=0.5cm of Z0] {};
\node[main,fill=black!100] (G1) [right=of G0,below=of Z1] {};
\node[main,fill=black!100] (G2) [right=of G1,below=of Z2] {};
\node[main,fill=black!100] (G3) [right=of G2,below=of Z3] {};
\node[main,fill=black!100] (G4) [right=of G3,below=of Z4] {};
\node[main,fill=black!100] (G5) [right=of G4,below=of Z5] {};
\node[main,fill=black!100] (G6) [right=of G5,below=of Z6] {};
\node[main,fill=black!100] (G7) [right=of G6,below=of Z7] {};
% Legend
\node[blockX, above = 0.04cm of Control](Treatment){};
\node [box2, draw=white!100, right= of Treatment, above = 0.05cm of Data1] (ClusterX) {Cluster \nodepart{two}HH};
\node[blockX, right = of ClusterX, above = 0.5cm of B0 ](Baseline){Base};
\node[blockX, right = of Baseline, above =0.5cm of L1 ](six){6};
\node[blockX, right = of six, above =0.5cm of L2](twelve){12};
\node[blockX, right = of twelve, above =0.5cm of L3](eighteen){18};
\node[blockX, right = of eighteen, above =0.5cm of L4](twentyfour){24};
\node[blockX, right = of twentyfour, above =0.5cm of L5](thirty){30};
\node[blockX, right = of thirty, above =0.5cm of L6](thirtysix){36};
\node[blockX, right = of thirtysix, above =0.5cm of L7](forty){40};
%
\path (B0) -- node[auto=false]{\ldots} (L1);
\path (L1)-- node[auto=false]{\ldots} (L2);
\path (L2)-- node[auto=false]{\ldots} (L3);
\path (L3)-- node[auto=false]{\ldots} (L4);
\path (L4)-- node[auto=false]{\ldots} (L5);
\path (L5)-- node[auto=false]{\ldots} (L6);
\path (L6)-- node[auto=false]{\ldots} (L7);
\path(O0)-- node[auto=false]{\ldots} (O1);
\path (O1)-- node[auto=false]{\ldots} (O2);
\path (O2)-- node[auto=false]{\ldots} (O3);
\path (O3) -- node[auto=false]{\ldots} (O4);
\path (O4)-- node[auto=false]{\ldots} (O5);
\path (O5) -- node[auto=false]{\ldots} (O6);
\path (O6) -- node[auto=false]{\ldots} (O7);
\path (W0) -- node[auto=false]{\ldots} (W1);
\path (W1) -- node[auto=false]{\ldots} (W2);
\path (W2)-- node[auto=false]{\ldots} (W3);
\path (W3) -- node[auto=false]{\ldots} (W4);
\path (W4)-- node[auto=false]{\ldots} (W5);
\path (W5) -- node[auto=false]{\ldots} (W6);
\path (W6) -- node[auto=false]{\ldots} (W7);
\path (Z0) -- node[auto=false]{\ldots} (Z1);
\path (Z1) -- node[auto=false]{\ldots} (Z2);
\path (Z2) -- node[auto=false]{\ldots} (Z3);
\path (Z3)-- node[auto=false]{\ldots} (Z4);
\path (Z4) -- node[auto=false]{\ldots} (Z5);
\path (Z5)-- node[auto=false]{\ldots} (Z6);
\path (Z6) -- node[auto=false]{\ldots} (Z7);
\path (G0) -- node[auto=false]{\ldots} (G1);
\path (G1)-- node[auto=false]{\ldots} (G2);
\path (G2)-- node[auto=false]{\ldots} (G3);
\path (G3) -- node[auto=false]{\ldots} (G4);
\path (G4) -- node[auto=false]{\ldots} (G5);
\path (G5)-- node[auto=false]{\ldots} (G6);
\path (G6) -- node[auto=false]{\ldots} (G7);
\end{tikzpicture}
\end{document}
答案1
像这样?
使用chains
库和循环后代码非常简洁:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{backgrounds,
calc, chains,
positioning,
shadings,
shapes}
\usepackage{amsmath}
\begin{document}
\begin{tikzpicture}[
node distance = 2mm and 7mm,
start chain = going below,
base/.style = {draw, font=\small},
box1/.style = {base, fill=blue!20, minimum width=24mm},
box2/.style = {rectangle split, rectangle split parts=2, inner sep=1mm},
main/.style = {circle, minimum size=3mm, inner sep=0mm,
shading=ball, ball color=blue!50,
node contents={}},
]
% cluster
\foreach \i in {1,...,5}
\node[box2, on chain] (B1\i) {600\nodepart{two} 30};
\node[box2, above=of B11] (B10) {Cluster\nodepart{two} HH};
% left blocks
\path let \p1 = ($(B11.north) - (B11.south)$),
\n1 = {veclen(\y1,\x1)} in
node[box1, minimum height=\n1, left=of B11] (A1) {Control};
\foreach \i [count=\j from 2] in {$S$, $S+F$, $S+F+B$, $S+F+B+N$}
\node[box1, left=of B1\j] (A\i) {\i};
% main nodes
\foreach \i [count=\j from 2] in {1,...,8}
\foreach \k in {1,...,5}
\node (B\j\k) [main, right=of B\i\k];
% labels above main nodes
\foreach \i [count=\j from 2] in {Base, 6, 12, 18, 24, 30, 36, 40}
\node at (B10 -| B\j1) {\i};
% dots between main nodes
\foreach \i in {1,...,5}
\foreach \j [remember=\j as \k (initially 2)] in {3,...,9}
\node at ($(B\k\i)!0.5!(B\j\i)$) {$\dotsm$};
\end{tikzpicture}
\end{document}