我是 tikz 新手,正在尝试生成带有多个拟合框的图表。这些框有锚标签,但我似乎无法让标签包裹在节点框内x1, a3, f3
。
我还想将所有这些框对齐到顶部边界,就像 nodexx1, a3
当前那样。
我该如何实现这个目标? 下面是代码和输出。
\documentclass{article}
\usepackage{tikz}
\usepackage{adjustbox}
\usetikzlibrary{ shapes.geometric, arrows, calc,
fit,
positioning,
}
\begin{document}
\resizebox{\textwidth}{!}{ \begin{tikzpicture}[
allnodes/.style={draw=black, thick, rounded corners,
minimum width=3cm, text width=10em, align=center,
minimum height=1cm},
boundbox/.style={rectangle, rounded corners, draw=black,inner xsep=2mm, inner ysep=4mm, text width=5em,draw},
vhilit/.style={draw=red, thick, dotted,
inner sep=1em},
hhilit/.style={draw=black, thick, densely dotted,
inner xsep=2em,
inner ysep=.5em},
line/.style={thick, -latex, shorten >= 2pt}
]
\node (p1) [allnodes] {jabberwocky fives: How four data can be four to sixers the sixers?};
\node (p2) [allnodes, below=0.75cm of p1] {jabberwocky crocodile for a sixers system};
\node (p3) [allnodes, below=0.75cm of p2] {jabberwocky heavens crocodile four heavens rolleres symptoms in four};
\node (p4) [allnodes, below=0.75cm of p3] {jabberwocky sixers in bus fives in crocodile};
\node (p5) [allnodes, below=0.75cm of p4] {jabberwocky sixers in four sixers heavens};
\node[boundbox, fit=(p1) (p2) (p3) (p4) (p5), label={[anchor=north]north:fives 1: four heavens in heavens}] (x1) {};
\node (e1) [allnodes, right=2cm of p1] {H1: crocodile four sixers four};
\node (e2) [allnodes, below=0.75cm of e1] {H2: crocodile four jabberwocky four Data heavens};
\node (e3) [allnodes, below=0.75cm of e2] {H1 vs H2: whizzbangs};
\node (e4) [allnodes, below=1.5cm of e3] {D1: crocodile four text fives rolleres};
\node (e5) [allnodes, below=0.75cm of e4] {D2: whizzbangs fives four only heavens rolleres symptoms};
\node (e6) [allnodes, below=0.75cm of e5] {D1 vs D2: whizzbangs of differential crocodile};
\node [boundbox, fit=(e1) (e2) (e3), label={[anchor=north]north:whizzbangs 1}] (a1) {};
\node [boundbox, fit=(e4) (e5) (e6), label={[anchor=north]north:whizzbangs 2}] (a2) {};
\node [boundbox,fit=(a1) (a2),label={[anchor=north]north:fives 2: four heavens rolleres crocodile for ill-heavens rolleres}] (a3) {};
\node (d1) [allnodes, right=2cm of e1] {A1: jabberwocky in RL, rolleres of crocodile};
\node (d2) [allnodes, below=0.75cm of d1] {H1 vs A1: whizzbangs of crocodile four sixers and sixers};
\node (d3) [allnodes, right=1cm of d1] {A2: jabberwocky in RL, four crocodile representation of new jabberwocky, rolleres of crocodile};
\node (d4) [allnodes, below=0.75cm of d3] {H2 vs A2: whizzbangs of crocodile four sixers and sixers};
\node [boundbox, fit=(d1) (d2), label={[anchor=north]north:whizzbangs 3}] (f1) {};
\node [boundbox, fit=(d3) (d4), label={[anchor=north]north:whizzbangs 4}] (f2) {};
\node [boundbox, fit=(f1) (f2), label={[anchor=north]north:fives 2: four heavens rolleres crocodile for ill-heavens problems}] (f3) {};
\end{tikzpicture}}
\end{document}
答案1
像这样?
\documentclass{article}
\usepackage[margin=20mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{chains,
fit,
positioning,
}
\makeatletter
\tikzset{reset join/.code={\def\tikz@lib@on@chain{}}}
\makeatother
\begin{document}
\begin{tikzpicture}[
node distance = 8mm and 6mm,
start chain = going below,
box/.style = {draw, thick, rounded corners,
text width=10em, align=left, minimum height=1cm,
font=\footnotesize,
on chain},
FITout/.style = {box, thin,inner xsep=1mm, inner ysep=6mm, yshift=12mm, fit=#1},
FITinn/.style = {FITout=#1,inner ysep=3mm, yshift=-2mm},
every label/.style = {text width=11em, align=center,
font=\footnotesize\linespread{0.84}\selectfont}
]
\node (p1) [box] {jabberwocky fives: How four data can be four to sixers the sixers?};
\node (p2) [box] {jabberwocky crocodile for a sixers system};
\node (p3) [box] {jabberwocky heavens crocodile four heavens rolleres symptoms in four};
\node (p4) [box] {jabberwocky sixers in bus fives in crocodile};
\node (p5) [box] {jabberwocky sixers in four sixers heavens};
\node[FITout={(p1) (p5)},
label={[anchor=north]{fives 1: four heavens in heavens}}] (x1) {};
%%
\node (e1) [box,
right=of p1] {H1: crocodile four sixers four};
\node (e2) [box] {H2: crocodile four jabberwocky four Data heavens};
\node (e3) [box] {H1 vs H2: whizzbangs};
\node (e4) [box] {D1: crocodile four text fives rolleres};
\node (e5) [box] {D2: whizzbangs fives four only heavens rolleres symptoms};
\node (e6) [box] {D1 vs D2: whizzbangs of differential crocodile};
\node [FITinn={(e1)(e3)},
label={[anchor=north]whizzbangs 1}] (a1) {};
\node [FITinn={(e4) (e6)},
label={[anchor=north]whizzbangs 2}] (a2) {};
\node [FITout={(a1) (a2)},
label={[anchor=north]{fives 2: four heavens rolleres crocodile for ill-heavens rolleres}}] {};
%%
\node (d1) [box,
right=of e1] {A1: jabberwocky in RL, rolleres of crocodile};
\node (d2) [box] {H1 vs A1: whizzbangs of crocodile four sixers and sixers};
\node (d3) [box,
right=4mm of d1] {A2: jabberwocky in RL, four crocodile representation of new jabberwocky, rolleres of crocodile};
\node (d4) [box] {H2 vs A2: whizzbangs of crocodile four sixers and sixers};
\node [FITinn={(d1) (d2)},
label={[anchor=north]whizzbangs 3}] (f1) {};
\node [FITinn={(d3) (d4)},
label={[anchor=north]whizzbangs 4}] (f2) {};
\node [FITout={(f1) (f2)},
label={[anchor=north, text width=21em]{fives 2: four heavens rolleres crocodile for ill-heavens problems}}] {};
\end{tikzpicture}
\end{document}
我会重新考虑最后一个节点列的设计。我认为如果框架在一列中会更好。然后您将能够使用更大的字体大小和更大的列间距离:
\documentclass{article}
\usepackage{geometry}
\usepackage{tikz}
\usetikzlibrary{chains,
fit,
positioning,
}
\begin{document}
\centering
\begin{tikzpicture}[
node distance = 8mm and 12mm,
start chain = going below,
box/.style = {draw, thick, rounded corners,
text width=11em, align=center, minimum height=1cm,
on chain},
FITout/.style = {box, thin,inner xsep=2mm, inner ysep=7mm, yshift=14mm, fit=#1},
FITinn/.style = {FITout=#1,inner ysep=4mm, yshift=-2mm},
every label/.style = {text width=11em, align=center,
font=\small\linespread{0.84}\selectfont}
]
\node (p1) [box] {jabberwocky fives: How four data can be four to sixers the sixers?};
\node (p2) [box] {jabberwocky crocodile for a sixers system};
\node (p3) [box] {jabberwocky heavens crocodile four heavens rolleres symptoms in four};
\node (p4) [box] {jabberwocky sixers in bus fives in crocodile};
\node (p5) [box] {jabberwocky sixers in four sixers heavens};
\node[FITout={(p1) (p5)},
label={[anchor=north]{fives 1: four heavens in heavens}}] (x1) {};
%%
\node (e1) [box,
right=of p1] {H1: crocodile four sixers four};
\node (e2) [box] {H2: crocodile four jabberwocky four Data heavens};
\node (e3) [box] {H1 vs H2: whizzbangs};
\node (e4) [box] {D1: crocodile four text fives rolleres};
\node (e5) [box] {D2: whizzbangs fives four only heavens rolleres symptoms};
\node (e6) [box] {D1 vs D2: whizzbangs of differential crocodile};
\node [FITinn={(e1)(e3)},
label={[anchor=north]whizzbangs 1}] (a1) {};
\node [FITinn={(e4) (e6)},
label={[anchor=north]whizzbangs 2}] (a2) {};
\node [FITout={(a1) (a2)},
label={[anchor=north]{fives 2: four heavens rolleres crocodile for ill-heavens rolleres}}] {};
%%
\node (d1) [box,
right=of e1] {A1: jabberwocky in RL, rolleres of crocodile};
\node (d2) [box] {H1 vs A1: whizzbangs of crocodile four sixers and sixers};
\node (d3) [box] {A2: jabberwocky in RL, four crocodile representation of new jabberwocky, rolleres of crocodile};
\node (d4) [box] {H2 vs A2: whizzbangs of crocodile four sixers and sixers};
\node [FITinn={(d1) (d2)},
label={[anchor=north]whizzbangs 3}] (f1) {};
\node [FITinn={(d3) (d4)},
label={[anchor=north]whizzbangs 4}] (f2) {};
\node [FITout={(f1) (f2)},
label={[anchor=north, text width=21em]{fives 2: four heavens rolleres crocodile for ill-heavens problems}}] {};
\end{tikzpicture}
\end{document}