TikZ 装饰标记不在路径上

TikZ 装饰标记不在路径上

我的问题与 TikZ 装饰有关标记

编译代码时没有错误 TeXLive网站

\documentclass[tikz]{standalone}
\begin{document}
\usetikzlibrary{decorations.markings}
\begin{tikzpicture}
\draw[preaction={decorate},decoration={markings,
mark=at position 0.15 with \arrow{latex},
mark=at position 0.25 with \arrow{latex},
mark=at position 0.35 with \arrow{latex},
mark=at position 0.45 with \arrow{latex},
mark=at position 0.55 with \arrow{latex},
mark=at position 0.65 with \arrow{latex},
mark=at position 0.2 with {\fill(0,0)circle(0.1);}, % should be on the curve❓
mark=at position 0.3 with {\fill(0,0)circle(0.1);}, % should be on the curve❓
mark=at position 0.4 with {\fill(0,0)circle(0.1);}, % on the curve✔️
mark=at position 0.5 with {\fill(0,0)circle(0.1);}, % on the curve✔️
mark=at position 0.6 with {\fill(0,0)circle(0.1);}, % on the curve✔️
mark=at position 0.7 with {\fill(0,0)circle(0.1);}, % on the curve✔️
}](-4.5,-0.5) .. controls (-3,2) and (-1,2) .. (-0.5,-0.5).. controls (0,-3) and (3,-5) .. (4,2.5);
\end{tikzpicture}
\end{document}

该路径是两条贝塞尔曲线的串联。

首先我在路径上放一些箭头,然后在路径上放一些黑点,但是前几个黑点不在路径上。

我尝试了另一种方法:编译代码时,没有错误 TeXLive网站

\documentclass[tikz]{standalone}
\begin{document}
\usetikzlibrary{decorations.markings}
\begin{tikzpicture}
\draw[preaction={decorate},decoration={markings,
mark=at position 0.2 with {\fill(0,0)circle(0.1);},
mark=at position 0.3 with {\fill(0,0)circle(0.1);},
mark=at position 0.4 with {\fill(0,0)circle(0.1);},
mark=at position 0.5 with {\fill(0,0)circle(0.1);},
mark=at position 0.6 with {\fill(0,0)circle(0.1);},
mark=at position 0.7 with {\fill(0,0)circle(0.1);},
mark=at position 0.15 with \arrow{latex}, % should be on the curve❓
mark=at position 0.25 with \arrow{latex}, % should be on the curve❓
mark=at position 0.35 with \arrow{latex}, % should be on the curve❓
mark=at position 0.45 with \arrow{latex}, % on the curve✔️
mark=at position 0.55 with \arrow{latex}, % on the curve✔️
mark=at position 0.65 with \arrow{latex}, % on the curve✔️
}](-4.5,-0.5) .. controls (-3,2) and (-1,2) .. (-0.5,-0.5).. controls (0,-3) and (3,-5) .. (4,2.5);
\end{tikzpicture}
\end{document}

首先我在路径上放一些黑点,然后在路径上放一些箭头,但是前几个箭头不在路径上。

答案1

出于某种原因,如果你把第一个标记按正确的顺序排列,它们都会属于正确的位置。我目前无法解释这一点,但至少,它是有效的。

编辑

添加@muzimuzhi 对此的评论:

多个mark=at position <pos> with <code>必须按<pos>升序排列,请参阅文档了解此选项:tikz.dev/library-decorations#pgf/装饰/标记

可以mark多次给出该选项,这样会应用多个标记。但在这种情况下,路径上的位置必须按递增顺序排列。

这里的奇怪行为在于最后一个是不是按递增顺序排列,但看起来位置似乎正确。 曲线上的标记(不)

\documentclass[tikz]{standalone}
\begin{document}
\usetikzlibrary{decorations.markings}
\begin{tikzpicture}
\draw[preaction={decorate},decoration={markings,
mark=at position 0.15 with \arrow{latex},
mark=at position 0.2 with {\fill(0,0)circle(0.1);},
mark=at position 0.25 with \arrow{latex},
mark=at position 0.3 with {\fill(0,0)circle(0.1);},
mark=at position 0.35 with \arrow{latex},
mark=at position 0.4 with {\fill(0,0)circle(0.1);},
mark=at position 0.5 with {\fill(0,0)circle(0.1);},
mark=at position 0.6 with {\fill(0,0)circle(0.1);},
mark=at position 0.7 with {\fill(0,0)circle(0.1);},
mark=at position 0.45 with \arrow{latex},
mark=at position 0.55 with \arrow{latex},
mark=at position 0.65 with \arrow{latex},
}](-4.5,-0.5) .. controls (-3,2) and (-1,2) .. (-0.5,-0.5).. controls (0,-3) and (3,-5) .. (4,2.5);
\end{tikzpicture}
\end{document}

相关内容