我想制作附加的 tikzpicture。首先,我如何将箭头更改为脚踝箭头?其次,我如何将节点对齐到顶部节点下方以跳过它们之间的节点?
代码
\begin{tikzpicture}
\node [io] (a){technical device};
\node [below=of a] (does) {Does it move?};
\node [below right= of does] (si) {Should it?};
\node [below left = of does] (si2) {Should it?};
\node [below left = of si2] (wd40) {WD-40};
\node [below right = of si2] (ok) {OK};
\node [below right= of si] (dt) {duct tape};
\draw[->]
(a) edge (does)
(does) -- ++(2.9,0)
|- (si.north)
(does) edge (si2)
(si2) edge (wd40)
(si2) edge (ok);
\end{tikzpicture}
编辑2:
\draw[->]
(a) edge (does)
(does) -- ++(2.9,0)
-| (si.north)
(does) edge (si2)
(si2) -- ++(-1.5,0)
-| (wd40.north)
(si2) -- ++(1.5,0)
-| (ok.north)
(si) -- ++(2,0)
-|(dt.north);
现在这些路径只是线条,为什么呢?
答案1
如果你真的想用tikz
而不是森林来绘制这棵决策树,你可以使用
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{shapes.geometric,positioning}
\begin{document}
\begin{tikzpicture}[%
decision/.style={diamond,draw, text width=4.5em, text badly centered,
inner sep=1pt},
io/.style={trapezium, trapezium left angle=70, trapezium right angle=110,
minimum width=3cm, minimum height=1cm, text centered,
draw=black,trapezium stretches=true},
block/.style={minimum width=2cm,draw},
forked/.style={to path={-| (\tikztotarget) \tikztonodes}},
node distance=1cm and 2cm
]
\node [io] (a){technical device};
\node [below=of a,decision] (does) {Does it move?};
\node [below right= of does,decision] (si) {Should it?};
\node [below left = of does,decision] (si2) {Should it?};
\node [below left=1cm and 1cm of si2,block] (wd40) {WD-40};
\node [below right=1cm and 1cm of si,block] (dt) {duct tape};
\path (wd40) -- node [block] (ok) {OK} (dt);
\draw[-stealth,semithick] (a) edge (does);
\draw[-stealth,semithick,forked,nodes={above,font=\sffamily}]
(does) edge node {yes}(si.north)
(does) edge node {no} (si2)
(si2) edge node {yes} (wd40)
(si2) edge node {no} (ok.160)
(si) edge node {yes} (ok.20)
(si) edge node {no} (dt);
\end{tikzpicture}
\end{document}
我添加了一个序言和一些样式。顺便说一句,如果有人告诉你这个库变得更好了quotes
,请谨慎对待这些说法。