3

From Zarko's answer to my preivous question by adding [short,...] I can insert a current arrow on any wire section and can specify color of both label and the arrow. That is great and satisfy in most cases.

\draw  (0,0) node[ocirc,scale=2] {} to [short, i>^= $I_L$, color=red, bipole current append style={color=red}] ++(0.5,0) to [cute inductor,
,bipole current append style={color=red}] ++( 1.5,0)  node[ocirc,scale=2]{} ;

enter image description here

Now if I don't use [short,..] I could do it like this but this would make the inductor red as well.

\draw  (0,-1) node[ocirc,scale=2] {}  to [cute inductor, i>^= $I_L$, color=red
,bipole current append style={color=red}] ++(2,0)  node[ocirc,scale=2]{} ;

enter image description here

Assuming that I want to place the inductor in the middle between two ends as in the second case, how can I do that? If I use [short,..] with very small distance like (0,0) [short,..] ++(0.1,0) it would place the arrow very close to the left terminal which is not desired.

The main reason for not using [short,...] is that I made a lot of circuits with TikZ and now if I change that then I would have to change all things as many of them depends on the inductor coordinate. Also in some cases, the built-in current arrow is good and you don't want to add [short] as it would probably require more space or make the inductor asymmetric as in the first image.

\documentclass[margin=3mm]{standalone}
\usepackage[american,siunitx,RPvoltages]{circuitikz}

\begin{document}


\begin{circuitikz}

\draw  (0,0) node[ocirc,scale=2] {} to [short, i>^= $I_L$, color=red, bipole current append style={color=red}] ++(0.5,0) to [cute inductor,
,bipole current append style={color=red}] ++( 1.5,0)  node[ocirc,scale=2]{} ;

\draw  (0,-1) node[ocirc,scale=2] {}  to [cute inductor, i>^= $I_L$, color=red
,bipole current append style={color=red}] ++(2,0)  node[ocirc,scale=2]{} ;
\end{circuitikz}


\end{document}
2
  • If I understood you correctly, you like in some cases inductor replace with straight lines. If I'm correct, than just drop it out and write longer short. If will be needed, I will write answer late afternoon.
    – Zarko
    Commented Dec 13, 2022 at 10:57
  • @Zarko nope, I want to keep in the center of two end points as the second image and with inductor black instead of red.
    – internet
    Commented Dec 13, 2022 at 11:02

2 Answers 2

3

I must confess, that question is not enterally clear to me. So, I guess, that you after:

enter image description here

\documentclass[margin=3mm]{standalone}
\usepackage[american,siunitx]{circuitikz}

\begin{document}

\begin{circuitikz}
\ctikzset{bipoles/capacitor/width/.initial=.075,
          current arrow scale=8,
          bipole current append style={color=red}}

\draw   (0,0)   node[ocirc] {}
                to [short, i=$I_{C}$, color=red]    ++ (0.75,0)
                to [cute inductor, v^=$V_L$, 
                    inductors/scale=0.8, color=red] ++ (1.5,0)
                node[ocirc] {};
\end{circuitikz}

\end{document}

Edit:
One try more, but I'm still not sure what you after ...

\documentclass[margin=3mm]{standalone}
\usepackage[american,siunitx]{circuitikz}

\begin{document}

\begin{circuitikz}
\ctikzset{bipoles/capacitor/width/.initial=.075,
          %current arrow scale=8,
          bipole current append style={color=red}}

\draw   (0,0)   node[ocirc] {}
                to [short, i=$I_{C}$, color=red]    ++ (0.55,0)
        (0,0)   to [cute inductor] ++ (2,0)
                node[ocirc] {};
\end{circuitikz}

\end{document}

enter image description here

5
  • I don't think this is different from my figure above. Let's assume that two distance between two points is 2. Now from the second image in my post, can you make the arrow and its label red without making the inductor red and without pushing the inductor to the right? Also the arrow postion is still same, not moving to the right.
    – internet
    Commented Dec 13, 2022 at 15:56
  • @internet, well than I didn't understood your question.
    – Zarko
    Commented Dec 13, 2022 at 16:14
  • Oh, the second one is what I'm looking for. I didn't know that you could specify the middle (0,0) like that. Thought that you need to make it in a chain and not come back like that.
    – internet
    Commented Dec 13, 2022 at 16:28
  • 1
    @internet, I can do only what is possible when I can understand the problem. Of course, second example is more or less dirty hack.
    – Zarko
    Commented Dec 13, 2022 at 16:31
  • I didn't know that trick and probably I can make my circuits smaller if I use that hack.
    – internet
    Commented Dec 13, 2022 at 16:33
3

Color is hard (especially in circuitikz). I was quite surprised that the solution offered for the first case works; it's not deliberate because, basically, it is very difficult, when drawing the shapes, to know which color is in force. Remember that the color is a path-global property, that red and color=red are not the same thing, and that rules are, well, difficult; the next example is plain TikZ, no circuitikz involved:

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[]
    \draw [thick, color=red] (0,0.2) -- ++(1,0) [color=blue] -- ++(1,0);
    \draw [thick, color=red] (0,0) -- ++(1,0) {[color=blue] -- ++(1,0)};
\end{tikzpicture}
\end{document}

enter image description here

...and additional nodes (like the current arrows or the labels) are added after the path is finished, so sometimes you really do not know which color should be acting now.

So, basically, the safe thing is to use only class colors (when they are provided) or use different paths. To help this situation, I added the "advanced voltage and current" (which should be called "by hand voltage and current", maybe); I would write your circuit like the following (I am throwing in a trick for big poles... had no time previously).

\documentclass[margin=3mm]{standalone}
\usepackage[american,siunitx,RPvoltages]{circuitikz}

\begin{document}

% define big poles...
\tikzset{% this definition is at tikz level, because
    % it will be used with a `node[... ]` element
    % the "nodes width" will be kept local
        bigO/.style={ocirc, circuitikz/nodes width=0.1},
    }
\ctikzset{% define new poles style
    O-/.style={bipole nodes={bigO}{none}},
    O-O/.style={bipole nodes={bigO}{bigO}},
    -O/.style={bipole nodes={none}{bigO}},
    !i/.style={no i symbols},
}
\newcommand{\iarronly}[2][red]{% name
\node [currarrow, color=#1, anchor=center,
rotate=\ctikzgetdirection{#2-Iarrow}] at (#2-Ipos) {};
}
\begin{circuitikz}
    % you need a quite new latex for mathcolor...
    \draw  (0,1) to[cute inductor, i>^=$\mathcolor{red}{I_L}$,
    name=LL, !i, O-O] ++(2,0) to[cute open switch] ++ (2,0);
    \iarronly{LL}% red is the default

    \draw  (0,0) to[cute inductor, i>^={\color{blue}$I_L$}, 
    name=LL1, !i, O-O] ++(2,0);
    \iarronly[blue]{LL1}
\end{circuitikz}

\end{document}

enter image description here

1
  • Thanks, it looks very nice.
    – internet
    Commented Dec 14, 2022 at 1:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .