tikz:在循环内命名路径时‘intersections’库中是否存在错误?

tikz:在循环内命名路径时‘intersections’库中是否存在错误?

我画了两个圆,并在\foreach循环内命名了它们的路径。尝试将这name intersections两条路径合并会引发错误,除非我命名第三条路径。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\foreach \s in {+,-} {
    \draw [name path={C\s}] (\s1,0) circle (1.5);}
\draw [name path=Ca] (0,1) circle (1.5);    % <- comment line to see error
\path [name intersections={of=C- and C+}];
\draw [dashed] (intersection-1) -- (intersection-2);
\end{tikzpicture}

\end{document}

如果没有注释掉标记的行,错误信息如下:

Package tikz Error: I do not know the path named `C-'. Perhaps you misspelt it. ...\path [name intersections={of={C-} and C+}];

对我来说,这似乎是一个错误。——或者我做错了什么?

答案1

draw如果在循环和交集命令之间插入一些命令,即使没有提到,它也会起作用name path。这很奇怪...

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}

\draw [name path=Ca] (0,1) circle (1.5);    % <- comment line to see error

\foreach \s in {+,-} {
    \draw [name path global ={C\s}] (\s1,0) circle (1.5);}

% \draw (0,1) circle (1.5) ; % uncomment this line take off the global parameter and it will work to without accessing to the pathes names ...

\path [name intersections ={of=C- and C+}];

\draw [dashed] (intersection-1) -- (intersection-2);

\end{tikzpicture}

\end{document}

相关内容