交叉点内的两个路径名不起作用。只有一个宏似乎有效。我尝试了所有宏扩展组合,但徒劳无功。以下“h\x and \vy”不起作用。令人厌烦的是,第一个参数“h\x”不能包含任何宏。交叉点有什么缺陷吗?提前致谢。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[name path=h1] (0,1) -- ++(3,0);
\draw[name path=h2] (0,2) -- ++(3,0);
\draw[name path=v1] (1,0) -- ++(0,3);
\draw[name path=v2] (2,0) -- ++(0,3);
\foreach \x in {1,2}
\foreach \y in {1,2}
\draw[fill,red,name intersections={of= h1 and v\y}] (intersection-1) circle (2pt);
%\draw[fill,red,name intersections={of= h\x and v\y}] (intersection-1) circle (2pt);% macro h\x doesn't work, why?
\end{tikzpicture}
\end{document}
答案1
您必须将第一个坐标括在{...}
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[name path=h1] (0,1) -- ++(3,0);
\draw[name path=h2] (0,2) -- ++(3,0);
\draw[name path=v1] (1,0) -- ++(0,3);
\draw[name path=v2] (2,0) -- ++(0,3);
\foreach \x in {1,2}
\foreach \y in {1,2}
\draw[fill,red,name intersections={of= {h\x} and v\y}] (intersection-1) circle (2pt);
\end{tikzpicture}
\end{document}