为什么以下测试无法\ifthenelse
编译:
\documentclass[border=30pt, tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{ifthen}
\usepackage{animate, calc}%%%%%%%%%%%%
\usepackage{animate}
\usepackage{circuitikz}
\begin{document}
\foreach \x in {0.1,0.2,...,4}{
\begin{tikzpicture}
\begin{circuitikz}
\draw (0,0)
to[V,v=$U_q$] (0,2) % The voltage source
to[short] (2,2)
to[R=$R_1$] (2,0) % The resistor
to[short] (0,0);
\draw (2,2)
to[short] (4,2)
to[R=$R_2$] (4,0)
to[short] (2,0);
\ifthenelse{\x<2}{\fill[color=red] (0,\x) circle (3pt);}{}
\end{circuitikz}
\end{tikzpicture}
}
\end{document}
编译时出现以下错误:
! Missing = inserted for \ifnum. <to be read
again>
答案1
它不起作用,因为\ifnum
(这就是\ifthenelse
调用的原因)只接受整数(没有分数)。因此您需要另一个测试。一个非常简单的尝试:
\documentclass[border=30pt, tikz]{standalone}
\usepackage{tikz,tikz-3dplot}
\usepackage{xparse}
\usepackage{animate, calc}%%%%%%%%%%%%
\usepackage{animate}
\usepackage{circuitikz}
\ExplSyntaxOn
\NewDocumentCommand { \xifnum } { }
{
\fp_compare:nTF
}
\ExplSyntaxOff
\begin{document}
\foreach \x in {0.1,0.2,...,4}{
\begin{tikzpicture}
\begin{circuitikz}
\draw (0,0)
to[V,v=$U_q$] (0,2) % The voltage source
to[short] (2,2)
to[R=$R_1$] (2,0) % The resistor
to[short] (0,0);
\draw (2,2)
to[short] (4,2)
to[R=$R_2$] (4,0)
to[short] (2,0);
\xifnum{\x<2}{\fill[color=red] (0,\x) circle (3pt);}{}
\end{circuitikz}
\end{tikzpicture}
}
\end{document}