测试了一下,就是\fill[color=red] (P-\i) circle (1pt);
这句代码有问题,说没有定义,但不太明白,向大佬请教.
报错信息如下:
Missing character: There is no ; in font nullfont!
! Undefined control sequence.
\UseTextAccent ...p \@firstofone \let \@curr@enc
\cf@encoding \@use@text@en...
l.20 \fill[color=red] (P-\i) circle (1pt);
以下为源码:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,intersections}
\begin{document}
\begin{tikzpicture}
\tikzset{
declare function={
f(\x)=cos(\x r);
g(\x)=\fpeval{1/3};
h(\x)=-0.5;
}
};
\draw[-Stealth] ({-2.1*pi},0)--({2.2*pi},0)node[below]{$x$};
\draw[-Stealth] (0,-1.5)--(0,1.5)node[left]{$y$};
\draw[name path=s,domain=-2*pi:2*pi,samples=600] plot (\x,{f(\x)});
\draw[name path=l,color=cyan,domain=-2*pi:2*pi,samples=600] plot (\x,{g(\x)});
\draw[name path=ll,color=cyan,domain=-2*pi:2*pi,samples=600] plot (\x,{h(\x)});
\path[name intersections={of=s and l,name=P,total=\t}];
\foreach \i in{1,...,\t}
\fill[color=red] (P-\i) circle (1pt);
\end{tikzpicture}
\end{document}
P.S. 遇到报错最好附上报错信息(给你补上了),更容易被其他人检索到关键词。
\tikzset
不需要;
\tikzset{
declare function={
f(\x)=cos(\x r);
g(\x)=\fpeval{1/3};
h(\x)=-0.5;
}
};
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,intersections}
\begin{document}
\begin{tikzpicture}
\tikzset{
declare function={
f(\x)=cos(\x r);
g(\x)=\fpeval{1/3};
h(\x)=-0.5;
}
}
\draw[-Stealth] ({-2.1*pi},0)--({2.2*pi},0)node[below]{$x$};
\draw[-Stealth] (0,-1.5)--(0,1.5)node[left]{$y$};
\draw[name path=s,domain=-2*pi:2*pi,samples=600] plot (\x,{f(\x)});
\draw[name path=l,color=cyan,domain=-2*pi:2*pi,samples=600] plot (\x,{g(\x)});
\draw[name path=ll,color=cyan,domain=-2*pi:2*pi,samples=600] plot (\x,{h(\x)});
\fill[name intersections={of=s and l,name=P,total=\t}]
[color=red] \foreach \i in {1,...,\t}{(P-\i) circle (1pt) node[above] {$\i$}};
\end{tikzpicture}
\end{document}
大佬,这个我查了的,我知道的,我想问的我上面的那个代码为什么不行
@u21174 related link and also another same solution by Qrrbrbirlbel
具体原因"似乎"是这个
\t
只是局部(local)的...而且这个宏怪怪(实际上是没定义,可见下图)的,没有储存了\t=4
的信息:@u70550 谢谢,明白原因了,但是前面的代码也没定义
\t
,为什么前面的代码就可以运行成功呢@u21174 你指的『前面的代码』是这个(或者说文档里面的)(?)
这里只有一个
;
,属于同一个语句(同一个\path
),\t
的local定义可以被\foreach
使用。@u70550 谢谢大佬,明白了