答案1
这定义了这种风格。它基于这个答案,并且实际上只适用于圆形节点。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning,quotes}
\usetikzlibrary{calc}
\tikzset{shifted path/.style args={from #1 to #2 with label #3}{insert path={
let \p1=($(#1.east)-(#1.center)$),
\p2=($(#2.east)-(#2.center)$),\p3=($(#1.center)-(#2.center)$),
\n1={veclen(\x1,\y1)},\n2={veclen(\x2,\y2)},\n3={atan2(\y3,\x3)} in
(#1.{\n3+180+asin(\pgfkeysvalueof{/tikz/shifted path/dist}/\n1)}) edge[/tikz/shifted path/arrows,"#3"] (#2.{\n3-asin(\pgfkeysvalueof{/tikz/shifted path/dist}/\n2)})
}},back and forth/.style={/utils/exec=\pgfkeys{/tikz/shifted path/.cd,#1},
shifted path=from \pgfkeysvalueof{/tikz/shifted path/from} to \pgfkeysvalueof{/tikz/shifted path/to} with label \pgfkeysvalueof{/tikz/shifted path/label 1},
shifted path=from \pgfkeysvalueof{/tikz/shifted path/to} to \pgfkeysvalueof{/tikz/shifted path/from} with label \pgfkeysvalueof{/tikz/shifted path/label 2}},
shifted path/.cd,dist/.initial=3pt,arrows/.style={-stealth},from/.initial=1,to/.initial=2,label 1/.initial={},label 2/.initial={}}
\begin{document}
\begin{tikzpicture}
\begin{scope}[every node/.style={draw, circle}]
\path (0,2) node(1){1} (6,2) node(2){2}
(0,0) node(3){3} (2,0) node(4){4} (4,0) node(5){6} (6,0) node(6){6};
\end{scope}
\begin{scope}[]
\draw[shifted path/arrows/.style={stealth-},
back and forth/.list={{from=1,to=2,label 1=3,label 2=1},
{from=1,to=3,label 1=2,label 2=5},
{from=2,to=6,label 1=4,label 2=14},
{from=3,to=4,label 1=8,label 2=12},
{from=4,to=5,label 1=7,label 2=15},
{from=5,to=6,label 1=11,label 2=17}}];
\end{scope}
\end{tikzpicture}
\end{document}
请注意,可以使用 方便地生成此图表tikz-cd
。