
Estoy intentando usar puntos de unión en circuitoikz solo en algunas iteraciones de un bucle, pero falla.
\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 correctamente no tiene puntos, pero quiero que R2 tenga puntos como en R0. ¿Cómo puedo hacer que esto funcione? (mi ejemplo real es más complicado y hacer este tipo de cosas me ahorraría mucho código repetitivo)
Respuesta1
El problema aquí es que \tikzset
(aunque usa la sintaxis antigua y mejor evitada) está configurando la clave /tikz/-*
(una flecha), como probablemente notó en los errores:
prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.
prova.tex|20 error| Package pgf Error: Unknown arrow tip kind '*'.
La clave correcta para los polos es /tikz/circuitikz/-*
, por lo que esto 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}
Mezclar \if
cosas en \foreach
bucles es bastante peligroso (aunque el problema aquí fue otro). Usaría \ifthenelse
aquí y un par de macros en lugar 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}
Si no quieres cargar ifthen
, la prueba
\ifnum\i=1\edef\maybedot{}\else\edef\maybedot{-*}\fi
también funciona.