如果我编译以下代码,则不会出现任何错误:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2,-2) grid (2,2);
\draw plot [mark=*, samples at= {22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\draw[shift={(0 cm, 2*sin(67.5) cm)}] plot [mark=*, samples at={22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\end{tikzpicture}
\end{document}
请注意,我使用向量 (0,2*sin(67.5)) 平移了第二个八边形,并且编译器似乎正确地解释了第二个分量。另一方面,当我尝试编译以下内容时:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2,-2) grid (2,2);
\draw plot [mark=*, samples at={22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\draw[shift={(2*cos(67.5) cm, 0 cm)}] plot [mark=*, samples at={22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\end{tikzpicture}
\end{document}
我收到一条错误消息:
! Package pgf Error: No shape named 2*cos(67 is known.
See the pgf package documentation for explanation.
Type H <return> for immediate help.
...
l.11 \draw[shift={(2*cos(67.5) cm, 0 cm)}]
plot [mark=*, samples at={22.5,67...
似乎它无法识别向量 (2*cos(67.5), 0),特别是 2*cos(67.5) 分量...有人能告诉我为什么吗?
提前致谢。
答案1
每当您()
在坐标的组件中时,都需要在组件周围加上括号,否则解析器会将结束部分视为坐标的)
结束)
。也就是说,您需要({<x expression with parens>}, {<y expression with parens>})
cm
另外,把 放在后面好像不行cos(67.5)
,但是你可以把它放在 后面2
。
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw [help lines] (-2,-2) grid (2,2);
\draw plot [mark=*, samples at={22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\draw[shift={({2cm*cos(67.5)}, 0cm)}] plot [mark=*, samples at={22.5,67.5,112.5,157.5,202.5,247.5,292.5,337.5,22.5}] (\x:1);
\end{tikzpicture}
\end{document}