我似乎已经name path
在为 Tikz 中最简单的用例而苦苦挣扎:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[name path=A,thick] (0,0) circle[radius=0.1];%
\draw[name path=B,thick] (1,1) circle[radius=0.1];%
\draw (A) -- (B);
\end{tikzpicture}
\end{document}%
这给了我:
Package pgf Error: No shape named A is known. \draw (A)
Package pgf Error: No shape named B is known. \draw (A) -- (B)
Package pgf Error: No shape named B is known. \draw (A) -- (B)
Package pgf Error: No shape named A is known. \draw (A) -- (B)
我究竟做错了什么?
答案1
从你的代码来看,你甚至可能不需要使用交集。让我们看看 MWE
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,positioning}
\begin{document}
\begin{tikzpicture}
\begin{scope}[local bounding box=what you want]
\path (0,0) node[circle,draw,thick,inner sep=1mm-\pgflinewidth] (A){}
(1,1) node[circle,draw,thick,inner sep=1mm-\pgflinewidth] (B){};%
\draw (A) -- (B);
\end{scope}
\node[above=of what you want]{Is this what you want?};
\begin{scope}[local bounding box=intersections,xshift=7cm,yshift=-1.9cm]
\draw[name path=A,thick] (0,0) circle[radius=2];%
\draw[name path=B,thick] (1,1) circle[radius=2];%
\draw[name intersections={of=A and B}] (intersection-1) -- (intersection-2);
\end{scope}
\node[above=of intersections]{What you can do with intersections};
\end{tikzpicture}
\end{document}%
左侧是两个对象(节点)之间的线,名为A
和B
。右侧是交点。当然,只有存在相交的路径时才能使用交点。这里计算了两个路径(不是节点!)和 的交点,A
并B
用线连接。
笔记:
- 节点和路径
A
是B
两个不同的对象。是的,你可以对和 Ti 使用相同的符号钾Z 不会感到困惑。 - 您也可以用字母来命名节点的路径。
我尝试用一个例子来说明第二点,其中节点的路径也有一个名称,并且在交叉点中使用。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\node[name path=A,circle,draw,text width=2cm] (B) at (0,0){I'm a node with
name B whose boundary path has the name A};
\draw[name path=C] (-4,4) -- (4,-4);
\draw[name intersections={of=A and C},latex-latex] (intersection-1)
to[bend right] (intersection-2);
\end{tikzpicture}
\end{document}%