如何将节点放置在 I 和 C 节点的交叉点 (I |- C)?MWE:
\documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{arrows,chains,positioning,shapes,scopes}
\begin{document}
\begin{tikzpicture}
[>=latex,node distance=.8cm,
start chain =going below,]
\tikzset{base/.style = {
draw,rounded corners,minimum width=20mm, minimum height=6mm, align=center,
inner sep=1mm, outer sep=0mm,
on chain, join=by {->}}}
\tikzset{start/.style={base,minimum size=6mm,circle,fill=black}}
\tikzset{end/.style={base,circle}}
\tikzset{box/.style={base}}
\tikzset{decision/.style={base,rounded corners=0,minimum size=6mm,diamond,aspect=1.5,on chain}}
{
\node[start] (A) {};
\node[box] (B) {clone repository};
\node[box] (C) {coding};
\node[box] (D) {commit locally};
\node[box] (E) {review};
\node[decision] (F) {};
{[start branch]
\node[box,left=2cm of F] (G) {rework};
\node[box,on chain=going above] (H) {recommit};
}
{[start branch]
\node[box,right=2cm of F] (I) {submit};
\coordinate (O) at (I |- C);
\node[box] at (O) (J) {update local repository};
}
\draw[->] (H) -- (E);
\draw[->] (J) -- (C);
% debug code line
\draw[red] (O) -- (I) (O) -- (C);
}
\end{tikzpicture}
\end{document}
答案1
节点位置不匹配J
是由节点on chain
的属性引起的box
。如果您在此取消此属性,节点将位于您希望的位置。
因为我不知道是否可以对链中的特定节点执行此操作,所以我重新组织了您的tikzset
so,该on chain
选项从中删除base
并添加到box
,稍后用于其他节点样式的样式定义。
通过这些变化以及连接线的一些变化(这在您的 MWE 中是不合逻辑的),我得到了以下图像:
这是您所寻找的吗?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, shapes}
\begin{document}
\begin{tikzpicture}[>=latex,
node distance = 8mm,
start chain = going below,
base/.style = {draw, rounded corners,
minimum width=20mm, minimum height=6mm,
align=center,
inner sep=1mm, outer sep=0mm,
},
box/.style = {base, on chain, join=by {->}},
start/.style = {box,minimum size=6mm,circle,fill=black},
end/.style = {box,circle, on chain},
decision/.style = {box, diamond, aspect=1.5,
sharp corners, minimum size=6mm}
]
\node[start] (A) {};
\node[box] (B) {clone repository};
\node[box] (C) {coding};
\node[box] (D) {commit locally};
\node[box] (E) {review};
\node[decision] (F) {};
{%[start branch]
\node[box,left=2cm of F] (G) {rework};
\node[box,on chain=going above] (H) {recommit};
}
{%[start branch]
\node[base,
right=2cm of F] (I) {submit};
\node[base] (J) at (I |- C) {update local repository};
}
\draw[->] (H) -- (E);
\draw[->] (F) -- (I);
% debug code line
\draw[red,->] (I) edge (J) (J) to (C);
\end{tikzpicture}
\end{document}