如何如图所示放置箭头?
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, bending, quotes, shapes.geometric}
\begin{document}
\begin{tikzpicture}
[-{stealth[bend]}, auto, very thick,
node distance=3cm,
shorten >=2pt, shorten <=2pt,
mynode/.style={circle,draw, thick, minimum size=8mm,
inner sep=2pt},
every edge quotes/.style={anchor=mid,circle,fill=white,
inner sep=1pt}
]
\node[mynode] (1) at (1,4) {1};
\node[mynode] (2) at (6,5) {2};
\node[mynode] (3) at (8,1) {3};
\node[mynode] (4) at (10,4){4};
\path[blue](1.east) edge["b"] (2.west)
(1.east) edge[bend left=30,"a"] (2.west)
(2.west) edge[bend left=30,"c"] (1.east)
(1.east) edge[bend right=30,"b"] (3.west)
(3.east) edge[bend right=40,"b"] (4.south)
(4.north west) edge[bend right=40,"c"] (2.east)
(2.south east) edge[bend left=30,"b"] (3.north);
\draw[blue] ([yshift=-2pt] 3.west) arc (-235:55:0.7)
node[midway,below] {a};
\draw[blue,line width=1mm,-{Stealth[bend]}] (-1,4) -- (1.west);
\end{tikzpicture}
\end{document}
答案1
像这样?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
bending,
decorations.markings,
quotes
}
\begin{document}
\begin{tikzpicture}[
shorten >=2pt, shorten <=2pt, arrows={[bend]},
->-/.style = {decoration={markings,
mark=at position 0.25 with {\arrow{Stealth}},
mark=at position 0.75 with {\arrow{Stealth}}},
very thick, draw=blue,
postaction={decorate}},
every edge/.style = {->-},
mynode/.style = {circle, draw, thick, minimum size=8mm, inner sep=2pt},
every edge quotes/.style = {circle, fill=white, anchor=mid, inner sep=1pt}
]
\node[mynode] (1) at (1,4) {1};
\node[mynode] (2) at (6,5) {2};
\node[mynode] (3) at (8,1) {3};
\node[mynode] (4) at (10,4){4};
\draw
(1) edge["b"] (2)
(1) edge[bend left,"a"] (2)
(2) edge[bend left,"c"] (1)
(1) edge[bend right,"b"] (3)
(3) edge[bend right=40,"b"] (4)
(4) edge[bend right=40,"c"] (2)
(2) edge[bend left,"b"] (3);
\draw[->-]
(3.195) arc (-240:60:0.8) node[midway,fill=white] {a};
\draw[blue,line width=1mm,-Stealth] (-1,4) -- (1.west);
\end{tikzpicture}
\end{document}
编辑: 添加的箭头指向循环,就像其他箭头一样。
答案2
我不想用白色覆盖所有东西,而是想添加弯曲的箭头。这可以通过show path construction
随附的装饰来实现。我添加了一种注重细节的decorations.pathreplacing
风格。mid label
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta, bending, quotes,shapes.geometric,decorations.pathreplacing}
\tikzset{mid label/.style={decoration={show path construction,
moveto code={},
lineto code={
\path (\tikzinputsegmentfirst)
-- (\tikzinputsegmentlast) foreach \X in {4,8} {coordinate[pos=0.1*\X] (aux-\X)}
node[midway,auto=false] (aux){#1};
\draw[-] (\tikzinputsegmentfirst) -- (aux);
\draw[->] (\tikzinputsegmentfirst) -- (aux-4);
\draw[-] (\tikzinputsegmentlast) -- (aux);
\draw[->] (aux) -- (aux-8);
},
curveto code={
\path (\tikzinputsegmentfirst) .. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..(\tikzinputsegmentlast)
foreach \X in {0,...,10} {coordinate[pos=0.1*\X] (aux-\X)}
node[midway,auto=false] (aux){#1};
\draw[-] plot[smooth,samples at={0,...,4}] (aux-\x) -- (aux);
\draw[->] plot[smooth,samples at={0,1,2,3}] (aux-\x);
\draw[-] plot[smooth,samples at={10,9,8,7,6}] (aux-\x) -- (aux);
\draw[<-] plot[smooth,samples at={8,7,6}] (aux-\x) -- (aux);
},
closepath code={
}
},decorate}}
\begin{document}
\begin{tikzpicture}
[>={Stealth[bend]}, auto, very thick,
node distance=3cm,
shorten >=2pt, shorten <=2pt,
mynode/.style={circle,draw, thick, minimum size=8mm,
inner sep=2pt},
every edge quo tes/.style={anchor=mid,circle,fill=white,
inner sep=1pt}
]
\node[mynode] (1) at (1,4) {1};
\node[mynode] (2) at (6,5) {2};
\node[mynode] (3) at (8,1) {3};
\node[mynode] (4) at (10,4){4};
\path ([yshift=-1cm]3.south) node (a){a};
\path[blue](1.east) edge[mid label=b] (2.west)
(1.east) edge[bend left=30,mid label=a] (2.west)
(2.west) edge[bend left=30,mid label=c] (1.east)
(1.east) edge[bend right=30,mid label=b] (3.west)
(3.east) edge[bend right=40,mid label=b] (4.south)
(4.north west) edge[bend right=40,mid label=c] (2.east)
(2.south east) edge[bend left=30,mid label=b] (3.north);
\draw[blue,->,shorten >=0,shorten <=0] (3) to[out=-150,in=180,looseness=1.5] (a);
\draw[blue,<-,shorten >=0,shorten <=0] (3) to[out=-30,in=0,looseness=1.5] (a);
\draw[blue,line width=1mm,->] (-1,4) -- (1.west);
\end{tikzpicture}
\end{document}