我有以下代码片段。在其中我使用操作定义节点 (B) coordinate
。不幸的是,我稍后无法访问该节点。LuaLatex 退出并显示错误消息:
Package pgf Error: No shape named B is known.
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=latex]
\tikzset{%
auto/.pic={%
\draw[fill=black!20] (0,10pt)
node[fill=black!20,anchor=south,
draw,rectangle,
minimum width=3cm,
minimum height=0.75cm] (-A) {};
\draw[fill=black]
($(-A.south west)!0.2!(-A.south east)$) circle (10pt);
\draw[fill=black]
($(-A.south west)!0.8!(-A.south east)$) circle (10pt);
}
}
% define node (B)
\draw[rotate=30,every node/.style={rotate=30}]
(0,0) coordinate (A) --
(4,0) pic (Auto) {auto} --
(8,0) coordinate (B);
\draw[->, line width=1pt]
(Auto-A.center) -- +(0,-2) node[midway,right]{$\vec F$};
% can't access (B)
\draw (A) -- (B);
\end{tikzpicture}
\end{document}
答案1
使用括号括住Auto
图片:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[>=latex,]
\tikzset{%
auto/.pic={%
\draw[fill=black!20] (0,10pt)
node[fill=black!20,anchor=south,
draw,rectangle,
minimum width=3cm,
minimum height=0.75cm] (-A) {};
\draw[fill=black]
($(-A.south west)!0.2!(-A.south east)$) circle (10pt);
\draw[fill=black]
($(-A.south west)!0.8!(-A.south east)$) circle (10pt);
}
}
% define node (B)
\draw[rotate=30,every node/.style={rotate=30}]
(0,0) coordinate (A) --
(4,0) {pic (Auto) {auto}} --
(8,0) coordinate (B);
\draw[->, line width=1pt]
(Auto-A.center) -- +(0,-2) node[midway,right]{$\vec F$};
% can access (B)
\draw (A) -- (B);
\end{tikzpicture}
\end{document}