下面的程式碼給出了No shape named S.corner 1 is known.
錯誤。我究竟做錯了什麼?
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[name=S,regular polygon, regular polygon sides=9, draw, minimum width=6cm] at (0,0) {};
\pic [draw, angle radius=.6cm] {angle = S.corner 1--S.corner 6--S.corner 5};
\end{tikzpicture}
\end{document}
答案1
tikzlibraryangles.code.tex
包含
\def\tikz@lib@rightangle@background#1--#2--#3\pgf@stop{%
\path [name prefix ..] [pic actions, draw=none] (#2.center)
-- ++(\tikz@start@angle@temp:\tikz@lib@angle@rad pt)
-- ++(\tikz@end@angle@temp:\tikz@lib@angle@rad pt)
-- ++(\tikz@start@angle@temp:-\tikz@lib@angle@rad pt)
-- cycle;
}%
從中您可以看到它附加.center
到第二個座標#2
。如果#2
已經是錨點,則這不起作用。要解決此問題(而不是重新定義\tikz@lib@rightangle@background
和附加的其他命令.center
),您可以只定義輔助座標。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{angles}
\usetikzlibrary{shapes}
\usetikzlibrary{shapes.geometric}
\begin{document}
\begin{tikzpicture}
\node[name=S,regular polygon,
regular polygon sides=9, draw, minimum width=6cm] at (0,0) {};
\path foreach \X in {1,...,9} {(S.corner \X) coordinate (corner \X)};
\pic [draw, angle radius=.6cm] {angle = corner 1--corner 6--corner 5};
\end{tikzpicture}
\end{document}