我怎样才能在循环索引上调节电路点?

我怎样才能在循环索引上调节电路点?

我尝试仅在循环的某些迭代中使用 circuitikz 中的连接点,但失败了。

\documentclass[border=6mm]{standalone}
\usepackage[siunitx, american]{circuitikz}
\begin{document}
\usetikzlibrary{calc}
\begin{tikzpicture}[
    font=\sffamily,
    every node/.style = {align=center}
]
\foreach[count=\i] \x in {0,3}
{
    \ifnum\i=1
    \tikzstyle{maybedot} = []
   \else
    \tikzstyle{maybedot} = [-*]
    \fi
     \draw (\x,0) to [R, l_={$R_\i$}, maybedot] (\x, 3) to [short, maybedot](\x,5);
}

     \draw (-2,0) to [R, l_={$R_0$ \\ noloop}, -*] (-2, 3) to [short, -*](-2,5);


\end{tikzpicture}
\end{document}

在此处输入图片描述

R1 正确地没有点,但我希望 R2 像 R0 一样有点。我该如何实现它?(我的真实示例更复杂,这样做可以节省大量重复代码)

答案1

这里的问题是,您\tikzset(尽管使用了旧的、最好避免的语法)正在设置键/tikz/-*(箭头),正如您可能在错误中注意到的那样:

prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.
prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.

杆子的正确键是/tikz/circuitikz/-*,因此其有效:

\documentclass[border=6mm]{standalone}
\usepackage[siunitx, american, RPvoltages]{circuitikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[
    font=\sffamily,
    every node/.style = {align=center},
    ]
    \foreach[count=\i] \x in {0,3}
    {
        \ifnum\i=1
            \ctikzset{maybedot/.style={}}
        \else
            \ctikzset{maybedot/.style={-*}}
        \fi
        \draw (\x,0) to [R, l_={$R_\i$}, maybedot] (\x, 3) 
            to [short,  maybedot](\x,5);
    }
    \draw (-2,0) to [R, l_={$R_0$ \\ noloop}, -*] (-2, 3) to [short, -*](-2,5);
\end{tikzpicture}
\end{document}

在循环中混合使用\if东西\foreach非常危险(尽管这里还有另一个问题)。我会\ifthenelse在这里使用几个宏来代替样式:

\documentclass[border=6mm]{standalone}
\usepackage{ifthen}
\usepackage[siunitx, american, RPvoltages]{circuitikz}
\usetikzlibrary{calc}

\begin{document}
\begin{tikzpicture}[
    font=\sffamily,
    every node/.style = {align=center},
    ]
    \foreach[count=\i] \x in {0,3}
    {
        \ifthenelse{\i = 1}{\edef\maybedot{}}{\edef\maybedot{-*}}
        \draw (\x,0) to [R, l_={$R_\i$}, \maybedot] (\x, 3) 
            to [short,  \maybedot](\x,5);
    }
    \draw (-2,0) to [R, l_={$R_0$ \\ noloop}, -*] (-2, 3) to [short, -*](-2,5);
\end{tikzpicture}
\end{document}

如果你不想加载ifthen,测试

\ifnum\i=1\edef\maybedot{}\else\edef\maybedot{-*}\fi

也有效。

三种可能的选择

相关内容