1

I'm trying to adap the answer here to add current flowing path to my circuit.
Unfortunately, the result is not same as in the reference above. I want to shift the current path up a bit.
How can I do that?

enter image description here

Does every node has all anchors such as north, south, east, west, north east, etc?
I saw this but couldn't make it works.

Also I would be much appreciated if you can help me change the arrow to something nicer. This \arrow{>=stealth} does not work as probably I don't understand how to use that.

\documentclass[border=1mm]{standalone} 
\usepackage[american,siunitx,RPvoltages]{circuitikz} 
\usetikzlibrary{decorations.markings} 
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture}

\ctikzset{ inductors/scale=0.5, capacitors/scale=0.5, sources/scale=0.5, switches/scale=0.5 }

\draw (0,0) coordinate (start) node[ocirc]{} to [cute open switch] ++(1,0) to [cute inductor, l^=$L$] ++(1,0) to [short]++(0.5,0) node[ocirc]{} coordinate (end);

% adding current \begin{scope}[on background layer, very thick, decoration = { markings, mark = at position 0.2 with {\arrow{>}}} ] \draw[line width = 2pt, red!40, postaction = {decorate}] (start.north)--(end.north); \end{scope}

\end{tikzpicture}

\end{document}

internet
  • 569

1 Answers1

2

All nodes has anchors such as north, south, east, west, north east, etc. A coordinate as you use here has no size, so all the anchors are at the same location. It is better to use arrows from arrows.meta than the old ones (Notice Stealth not stealth).

\documentclass[tikz, border=1cm]{standalone} 
\usepackage[american, siunitx, RPvoltages]{circuitikz} 
\usetikzlibrary{decorations.markings, arrows.meta} 
\usetikzlibrary{backgrounds}

\begin{document}

\begin{tikzpicture} \ctikzset{inductors/scale=0.5, capacitors/scale=0.5, sources/scale=0.5, switches/scale=0.5} \draw (0,0) coordinate (start) node[ocirc]{} to [cute open switch] ++(1,0) to [cute inductor, l^=$L$] ++(1,0) to [short]++(0.5,0) node[ocirc]{} coordinate (end); \begin{scope}[on background layer, decoration={ markings, mark=at position 0.2 with {\arrow{Stealth[scale=0.8]}}} ]
\draw[ultra thick, red!40, postaction={decorate}] ([yshift=1pt]start) -- ([yshift=1pt]end);
\end{scope} \end{tikzpicture} \end{document}

A small circuit wit red arrow in background

Or as in comments:

\draw[ultra thick, red!40, postaction={decorate}, transform canvas={yshift=1pt}] (start) -- (end);
  • Very nice, thank you! If the path is not straight lines, do I have to specify the shift for every points? I'm thinking if I'll have to add xshift or yshift for every points. I still don't get how does that work for the reference one but not here. I think the reference one also nodes with no size? – internet Dec 14 '22 at 13:28
  • 1
    You could use \draw[ultra thick, red!40, postaction={decorate}, transform canvas={yshift=1pt}] (start) -- (end); to move the whole path. This comes with its own limitations and dangers. – hpekristiansen Dec 14 '22 at 13:33
  • Yeah, that is shorter but I can only do that with straight line. Probably I could define node instead of coordinate so I can make it simple as in the link. – internet Dec 14 '22 at 13:40
  • No you can do that with any path: \draw[transform canvas={yshift=1pt}] (0,0) -- (1,0) -- (1,1); – hpekristiansen Dec 14 '22 at 13:45
  • How about this? For the circuit I changed it to this \draw (0,0) coordinate (start) node[ocirc]{} to [cute open switch] ++(1,0) to [cute inductor, l^=$L$] ++(1,0) to [short]++(0.5,0) node[ocirc]{} coordinate (end) to [cute open switch] ++(0,-1) node[ground]{} coordinate (ground); and then \draw[ultra thick, red!40, postaction={decorate}, transform canvas={yshift=3pt}] (start) --(end)-- (ground); to draw but it does not work for the second section to ground. https://ibb.co/Ykd7Tp4

    I don't expect this would work though. The second section I shuold shift x to the right instead.

    – internet Dec 14 '22 at 13:57
  • more on transformations can be found here: https://tikz.dev/base-transformations. Be careful using the more advanced levels of transformation. – anis Dec 14 '22 at 14:01
  • 1
    It does work, but your ground coordinate is not where you want it, you could name the node instead like this: ... node[ground] (ground) {};. If you need further help, then please edit your question or ask a new question. – hpekristiansen Dec 14 '22 at 14:04
  • Thanks, I'll ask a new question as it does not seem to relate to this. – internet Dec 14 '22 at 14:35