我正在尝试在 tikpiz 中创建此状态图,但 C5、C6、C7 侧面的箭头有问题。如果可能的话,我想弯曲 C8 和 C10,您有什么建议吗?
参考图:
我目前的尝试:
请参阅我的乳胶代码:
\begin{figure}[h!tb]
%\raggedleft
\centering
\begin{tikzpicture}[scale = 1]
\footnotesize
[>=stealth',shorten >=1pt,node distance=2cm,on grid,auto,initial text=, every state/.style={rectangle, width=5cm, minimum height=0.8cm}, every link/.style {thick, shorten >=2pt, shorten <=2pt}]
\node[align=center] (E) at (0,0) [rectangle,draw,text width=3cm, minimum height=1cm] {Enrolment};
\node[align=center] (F) at (0,-2) [rectangle,draw,text width=3cm, minimum height=1cm] {First year};
\node[align=center] (S) at (0,-4) [rectangle,draw,text width=3cm, minimum height=1cm] {Second year};
\node[align=center] (A) at (6,-4) [rectangle,draw,text width=3cm, minimum height=1cm] {Attrition};
\node[align=center] (T) at (0,-6) [rectangle,draw,text width=3cm, minimum height=1cm] {Third year};
\node[align=center] (G) at (0,-8) [rectangle,draw,text width=3cm, minimum height=1cm] {Graduate};
\path[->]
(E) edge (F)
(E) -- (F) node[midway, circle, draw,fill=white!20] {?}
(F) edge (S)
(F) -- (S) node[midway, circle, draw,fill=white!20] {?}
(S) edge (T)
(S) -- (T) node[midway, circle, draw,fill=white!20] {?}
(T) edge (G)
(T) -- (G) node[midway, circle, draw,fill=white!20] {?}
(S) edge (A)
(S) -- (A) node[midway, circle, draw,fill=white!20] {?}
(F.east) edge (A.north)
(F.east) -- (A.north) node[midway, circle, draw,fill=white!20] {?}
(T.east) edge (A.south)
(T.east) -- (A.south) node[midway, circle, draw,fill=white!20] {?} ;
\path
(F.west) edge[transform canvas={xshift=-3mm}] (G.west)
(F.west) -- (G.west) node[transform canvas={xshift=-1.5mm}, midway, circle, draw,fill=white!20] {?} ;
(F.west) -- (G.west) node[transform canvas={xshift=-3mm},midway,draw] {?} ;
\end{tikzpicture}
\end{figure}
答案1
让我稍微清理一下并使用一些不错的库:
arrows.meta
对于箭头:> = Latex
chains
将节点放在一行中的简单方法:start chain
every join
join = by …
- 节点自动命名
<chain name>-<n>
,<n>
默认<chain name>
为链
positioning
(由 加载chains
)以便更好地定位相对于彼此的节点:right = of …
above = of …
- 由库使用
chains
并使用给定的node distance
ext.paths.ortho
更多正交路径选项:ortho/install shortcuts
获得-|
安装的密钥-|
路径操作对于边→C8 和 C9- 路径
r-lr
操作(通过lr
键安装)→C5、C6 和 C7
quotes
有一个很好的捷径(见quotes mean question mark
)将问号放在路径上- 这会放置一个带有 的节点,该节点位于
?
路径上,标签位于那具有给定文本的节点
- 这会放置一个带有 的节点,该节点位于
代码
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, chains, ext.paths.ortho, quotes}
\tikzset{
nudge up/.style={yshift={ (#1)*2mm}}, nudge up/.default=1,
nudge down/.style={yshift={-(#1)*2mm}}, nudge down/.default=1,
/utils/temp/.style={#1/.style={ortho={#1 distance={##1}},to path={r-#1(\tikztotarget)\tikztonodes}}},
/utils/temp/.list={rl, lr, du, ud},
qm/.style={circle, draw, fill=white, inner sep=+.15em},
quotes mean question mark/.style={
edge quotes mean={edge node={node[qm, label={[direction shorthands,##2]##1}]{?}}}}}
\begin{document}
\begin{tikzpicture}[
>=Latex,
box/.style={rectangle, draw, text width=3cm, align=center, minimum height=1cm},
node distance=1.5cm and 2cm,
start chain=going below,
every join/.append style={->},
quotes mean question mark
]
\foreach[count=\i from 0] \t in {Enrolment, First Year, Second year, Third year, Graduate}
\node[on chain, box, join=by "C\i" right]{\t};
\node[box, right=of chain-3] (chain-a) {Attrition};
\path[every join, ortho/install shortcuts, ortho/middle 0 to 1]
([nudge down] chain-2.west) edge[lr, near start, "C5" right] (chain-4)
([nudge up] chain-2.west) edge[lr=15mm, pos=.3, "C6" right] ([nudge down] chain-5.west)
(chain-3) edge[lr=10mm, near end, "C7" right] ([nudge up] chain-5.west)
(chain-2) edge[-|, near start, "C8" below] (chain-a)
(chain-3) edge[ "C9" below] (chain-a)
(chain-4) edge[-|, near start, "C10"below] (chain-a)
;
\node[circle, fill, draw, above=of chain-begin, "Entry Point" right] {} edge[every join] (chain-begin);
\end{tikzpicture}
\end{document}