我尝试使用 Tikz 绘制下面的图片,但收到了该问题标题中的错误消息。
这是我正在使用的代码。请注意,当我尝试插入节点时出现错误消息$v_0$
。有人能告诉我这里出了什么问题吗?
\begin{tikzpicture}
\def\fin{3} %... end of the slope
\def\bot{-2} %... height of the slope
\def\mp{2} %... x-coordinate of final moto's position
%... environment
\draw[gray!50,fill=gray!50,very thick]
(-2,0)--
(0,0)--
(\fin,\bot)--
(\fin+1,\bot)--
(\fin+1,\bot-0.2)--
(-2,\bot-0.2)--cycle
;
%-> DEFINE THE MOTO PICTURE (#1=size, #2=location, #3=rotation)
\def\moto#1#2#3{
\def\wd{#1} %... wheel axis distance and moto height
\def\wr{#1/4} %... wheel radius
\def\pos{#2++(0,\wr)} %... position of the very bottom point of the wheel
%... wheels
\draw[gray!50,very thick]
\pos circle(\wr)
{\pos+({#3}:\wd)} circle(\wr)
;
%... chassis
\draw[gray!50,fill=gray!50]
{\pos+({#3+120}:{6*\wr/5})} arc({120+#3}:{#3}:{6*\wr/5})--++
({#3}:{\wd-12*\wr/5}) arc({#3+180}:{#3+60}:{6*\wr/5})--++
({#3+90}:{\wr/5}) arc({#3+60}:{#3+90}:{9*\wr/5})--++
({#3+120}:{\wr})--++
({#3+210}:{2*\wr})--++
({#3+180}:{3*\wr})
;
%... motorcyclist
\draw[gray!50,line width={4*\wd}]
{\pos+({#3+60}:{6*\wr/5})}--++
({#3+60}:{3*\wr})
{\pos++({#3+60}:{4*\wr})} circle({2*\wr/3})
{\pos++({#3+60}:{3*\wr})}--++
({#3-10}:{2*\wr})
;
%... velocity vector
%\draw[->,gray!50,very thick]
% {\pos++({#3}:{\wd})++({#3+90}:{\wr})}--++
% ({#3}:{\wd})% node[above]{$v_0$}
% ;
}
%... the sizes
\draw[<->,thick,white]
(0,0)--
(0,\mp*\bot/\fin) node[midway,fill=gray!50]{$h$}
;
\draw[<->,thick,white]
(0,\mp*\bot/\fin-0.1)--
(\mp,\mp*\bot/\fin-0.1) node[midway,fill=gray!50]{$x$}
;
\draw[gray!50,dashed,thick]
(-0.5,0.25)--
(0,0.25) to[out=0,in=100]
(\mp+0.25,{(\mp+0.25)*\bot/\fin})
;
\moto{0.5}{(-1.5,0)}{0}
\draw[->,gray!50,very thick]
(-1,0.3)--
(-0.5,0.3)% node[above]{$v_0$}
;
\draw[gray!50]
(-0.5,0.3) node[above]{$v_0$}
;
\moto{0.5}{(\mp,\mp*\bot/\fin)}{atan(\bot/\fin)}
\end{tikzpicture}
答案1
问题在于您重新定义了 TeX 的\wd
基元,该基元获取框的宽度。尝试以下示例,取消注释\def\wd{0.5}
(这是您调用时代码执行的操作\moto{0.5}
):
\documentclass{article}
\begin{document}
\newbox\tempbox
\setbox\tempbox\hbox{Don't \emph{ever} redefine \TeX's internals.}
% \def\wd{0.5}
The width of the following warning is: \the\wd\tempbox
\box\tempbox
\end{document}
一旦你改变\wd
一些 TeX 未使用的东西,它就会起作用。
这是 LaTeX 的\newcommand
如果命令已经定义,则会引发错误:错误消息会所有的如果你重新定义一些不该定义的东西,会更有趣。