我想用 TikZ 绘制此图像:
我写了这段代码:
\documentclass{standalone}
\usepackage{amsmath,amsfonts,amssymb,amsthm}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.markings}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{calc}
\tikzset{dot/.style =
{circle,
draw=blue,
line width=.5pt},
dot/.default = 4pt
}
\tikzset{
% style to apply some styles to each segment of a path
on each segment/.style={
decorate,
decoration={
show path construction,
moveto code={},
lineto code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
curveto code={
\path [#1] (\tikzinputsegmentfirst)
.. controls
(\tikzinputsegmentsupporta) and (\tikzinputsegmentsupportb)
..
(\tikzinputsegmentlast);
},
closepath code={
\path [#1]
(\tikzinputsegmentfirst) -- (\tikzinputsegmentlast);
},
},
},
% style to add an arrow in the middle of a path
mid arrow/.style={postaction={decorate,decoration={
markings,
mark=at position .5 with {\arrow[scale=1.5,#1]{stealth}}
}}},
}
\begin{document}
\begin{tikzpicture}[line cap=round]
% First, define nodes
\draw (0, 0) node[
inner sep=0pt,
fill=black,
label={left:{$\boldsymbol{M}$}}
] (M) {};
\draw (2, -2) node[
inner sep=0pt,
fill=black,
label={above:{$\boldsymbol{Q}$}}
] (Q) {};
\draw (5, -1) node[
inner sep=0pt,
fill=black,
label={above:{$\boldsymbol{P}$}}
] (P) {};
\draw (4, 1.5) node[
inner sep=0pt,
fill=black,
label={right:{$\boldsymbol{O}$}}
] (O) {};
\draw (1, 1.5) node[
inner sep=0pt,
fill=black,
label={above:{$\boldsymbol{N}$}}
] (N) {};
% Draw curved path
\path [very thick, draw=black, postaction={very thick, on each segment={mid arrow=black}}]
(M) to [bend left=100] (N)
(M) to [bend left=40] (N)
(M) -- (N)
(M) to [bend right=40] (N)
(M) to [bend right=100] (N);
\end{tikzpicture}
\end{document}
按照圆的规定,边的主边和端点与形状不相似。有没有更简单更好的方法来做到这一点?
答案1
我必须承认,我迷失在你的 MWE 中,所以我决定从头开始编写它,以便它尽可能与提供的草图相似。但是,图像的代码更简单、更短(至少在我看来),图像更漂亮(再次符合我的品味):
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
decorations.markings,
ext.arrows, % defined in the tikz-ext package
positioning}
\tikzset{dot/.style = {circle, fill, thick, inner sep=2pt, outer sep=0pt,
node contents={} },
every edge/.style = {draw, thick,
decoration={markings,
mark=at position 0.5 with {\arrow[very thick,scale=0.6] {Centered Straight Barb}}
},
postaction={decorate},
},
every label/.style = {anchor=center, label distance = 1.7ex},
bend angle = 25
}% end of tikzset
\begin{document}
\begin{tikzpicture}
% First, define nodes
\foreach \i [count=\j from 0] in {M,Q,P,O,N}
\path (0,0) -- (180+\j*72:2) node[label=180+\j*72:\i] (\i) [dot];
% Draw curved arrows
\draw
(M) edge [bend left=55] (N)
(M) edge [bend left] (N)
(M) edge (N)
(M) edge [bend right] (N)
(M) edge [bend right=55] (N);
\draw
(N) edge [bend left] (O)
(N) edge [bend right] (O);
\draw
(O) edge [bend left=55] (P)
(O) edge [bend left] (P)
(O) edge [bend right] (P)
(O) edge [bend right=55] (P);
\draw
(M) edge [bend left] (Q)
(M) edge (Q)
(M) edge [bend right] (Q);
\draw
(Q) edge [bend left] (P)
(Q) edge (P)
(Q) edge [bend right] (P);
\end{tikzpicture}
\end{document}