我正在构建几条曲线,它们的构造方式各不相同,但它们的路径名称为=lambda1,...,lambda4。后来,我将它们与一条路径相交。附件是一个可行最小示例。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\path[name path=t1] (6,0) -- (6,7);
\draw[name path=lambda1] (0,4) -- (7,3.5);
\draw[name path=lambda2](0,2.5) sin (7,4.5);
\draw[name path=lambda3] (3,0) parabola (7,5);
\draw[name path=lambda4] (2,0) .. controls (3,4) .. (7,7);
\fill [red, name intersections={of=lambda1 and t1}] (intersection-1) circle (2pt) node [below] {$\lambda_1$};
\fill [red, name intersections={of=lambda2 and t1}] (intersection-1) circle (2pt) node[below] {$\lambda_2$};
\fill [red, name intersections={of=lambda3 and t1}] (intersection-1) circle (2pt) node[below] {$\lambda_3$};
\fill [red, name intersections={of=lambda4 and t1}] (intersection-1) circle (2pt) node[below] {$\lambda_4$};
\end{tikzpicture}
\end{document}
最后 4 行需要一个 \foreach,但我无法让它完全工作。对我来说,似乎
\foreach \n in {1,...,4} {
\fill [red, name intersections={of=lambda\n and t1}]
(intersection-1) circle (2pt) node[below] {$\lambda_\n$};}
应该是正确的解决方案,但事实并非如此。然而,
\foreach \n in {1,...,4} {
\fill[red, name intersections={of=t1 and lambda\n}]
(intersection-1) circle (2pt) node[below] {$\lambda_\n$};}
运行良好。我这里遗漏了什么?
答案1
如果lambda\n
通过将其括在内进行分组{...}
,则它可以工作:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\path[name path=t1] (6,0) -- (6,7);
\draw[name path=lambda1] (0,4) -- (7,3.5);
\draw[name path=lambda2](0,2.5) sin (7,4.5);
\draw[name path=lambda3] (3,0) parabola (7,5);
\draw[name path=lambda4] (2,0) .. controls (3,4) .. (7,7);
\foreach \n in {1,...,4} {
\fill [blue, name intersections={of={lambda\n} and t1}]
(intersection-1) circle (2pt) node[below] {$\lambda_\n$};
}
\end{tikzpicture}
\end{document}