
Estou tentando usar pontos de junção no circuitikz apenas em algumas iterações de um loop, mas falha.
\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 corretamente não tem pontos, mas quero que R2 tenha pontos como em R0. Como posso fazer isso funcionar? (meu exemplo real é mais complicado e fazer esse tipo de coisa me pouparia de muito código repetitivo)
Responder1
O problema aqui é que você \tikzset
(embora use a sintaxe antiga e melhor evitada) está configurando a chave /tikz/-*
(uma seta), como você provavelmente notou nos erros:
prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.
prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.
A chave correta para polos é /tikz/circuitikz/-*
, então funciona:
\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}
Misturar \if
coisas em \foreach
loops é bastante perigoso (embora o problema aqui fosse outro). Eu usaria \ifthenelse
aqui algumas macros em vez de estilos:
\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}
Se você não quiser carregar ifthen
, o teste
\ifnum\i=1\edef\maybedot{}\else\edef\maybedot{-*}\fi
também funciona.