路径上的节点是否有第三种选择,即“在”而不是above
或below
?默认值似乎是above
。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,auto,>=latex, every node/.style={
font=\sffamily\scriptsize
},
circtext/.style={draw,circle,minimum size=8pt,inner sep=2pt},
dot/.style={draw,circle,fill=black,minimum size=0.6mm,inner sep=0pt}
]
{
\node[circtext, fill=yellow](A) at (0,0) {A};
\node[circtext, fill=yellow, right=of A](B){B};
\draw[->] (A) -- node[dot, pos=0.5, above](C){}(B);
}
\end{tikzpicture}
\end{document}
如果我使用below
我会得到这个:
但我想要在路径,不在上方或下方。
答案1
即使处于auto
活动状态,您也可以强制on path
添加节点选项进行放置anchor=center
:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,auto,>=latex, every node/.style={
font=\sffamily\scriptsize
},
circtext/.style={draw,circle,minimum size=8pt,inner sep=2pt},
dot/.style={draw,circle,fill=black,minimum size=0.6mm,inner sep=0pt}
]
{
\node[circtext, fill=yellow](A) at (0,0) {A};
\node[circtext, fill=yellow, right=of A](B){B};
\draw[->] (A) -- node[dot, pos=0.25](C){}
node[dot, pos=0.5, anchor=center](C){}
node[dot, pos=0.75, below](C){}(B);
}
\end{tikzpicture}
\end{document}
答案2
尝试
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning}
\begin{document}
\begin{tikzpicture}[node distance=2cm,>=latex, every node/.style={
font=\sffamily\scriptsize
},
circtext/.style={draw,circle,minimum size=8pt,inner sep=2pt},
dot/.style={draw,circle,fill=black,minimum size=0.6mm,inner sep=0pt}
]
{
\node[circtext, fill=yellow](A) at (0,0) {A};
\node[circtext, fill=yellow, right=of A](B){B};
\draw[->] (A) -- node[dot](C){} (B);
}
\end{tikzpicture}
\end{document}
我只省略了选项auto
,这会导致节点自动定位在路径上方或下方。