![路径中的中心箭头](https://linux22.com/image/351233/%E8%B7%AF%E5%BE%84%E4%B8%AD%E7%9A%84%E4%B8%AD%E5%BF%83%E7%AE%AD%E5%A4%B4.png)
我怎样才能将箭头放置在边缘的中心?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\usepackage{tkz-graph}
\usetikzlibrary{decorations.markings}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=4cm,on grid,auto]
\node[state] (s_0) {$s_0$};
\node[state] (s_1) [right=of s_0] {$s_1$};
\path[->]
(s_0) edge node {0} (s_1)
(s_1) edge [bend right=45] node [above] {1} (s_0)
;
\end{tikzpicture}
\end{document}
针对这个问题给出了几个很好的答案\draw
,例如Tikz:箭头位于中心但应用相同的机制会\path
出现错误:“我无法装饰空路径”
答案1
只需将选项添加[->-=.5]
到边缘即可,如下所示:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{decorations.markings}
\tikzset{->-/.style={decoration={
markings,
mark=at position #1 with {\arrow{>}}},postaction={decorate}}}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,shorten <=1pt,node distance=4cm,on grid,auto]
\node[state] (s_0) {$s_0$};
\node[state] (s_1) [right=of s_0] {$s_1$};
\path
(s_0) edge[->-=.5] node {0} (s_1)
(s_1) edge [bend right=45,->-=.5] node [above] {1} (s_0);
\end{tikzpicture}
\end{document}