1

I tried to look at these previous posts to solve my problem:

  1. Coloring the current arrows
  2. Coloring the current label

It seems that the solutions proposed by these posts reprogram the colour of all the current flow in the figure. What I am trying to do is if SELECTIVELY changing the colour of the current arrows on my diagram. On the following network, I am trying to colour the complete I1(t) arrow in red (not just the tip of the arrow is coloured in my MWE) and leave Ic(t) in black including the tip of the arrow.

    \documentclass{standalone}
    \usepackage{circuitikz}

    \makeatletter
    \ctikzset{current arrow color/.initial=black}% create key

    \pgfdeclareshape{currarrow}{
    \anchor{center}{
    \pgfpointorigin
    }
    \anchor{tip}{
    \pgfpointorigin
        \pgf@circ@res@step = \pgf@circ@Rlen
            \divide \pgf@circ@res@step by 16
    \pgf@x  =\pgf@circ@res@step
    }
\behindforegroundpath{      

    \pgfscope
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by 16

        \pgfpathmoveto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{.8\pgf@circ@res@step}}
        \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}           
        \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/current arrow color}}
        \pgfusepath{draw,fill}

    \endpgfscope
    }
    }
    \makeatother

    \begin{document}

    \ctikzset{voltage/distance from node=.8}

    \begin{circuitikz}[american]
    \draw[circuitikz/current arrow color=red]
    % bottom line           
       (0,0) to [short, o-] (9,0)
        % shunt branches            
       (2,0) to [C, *-*,l={$C/2$},v=$V_C$,f>^=$I_C(t)$] (2,3)
       (9,0) to [C, *-*,l=$C/2$,n=C2] (9,3)     
        % top line          
       (0,3) to [short,o-] (3,3)
       to [R, l_=$R_1$,i={\color{\pgfkeysvalueof{/tikz/circuitikz/current arrow color}}$I_1$},f>^=$\color{red}I_1(t)$] (9,3)
     % Input and output labels
     (C2.s)  node[right] {$V_s$};% anchors rotated
    \end{circuitikz}
    \end{document}
1

1 Answer 1

2

This also modifies the flowarrow shape, and splits the diagram into two draws. (IIRC, you can't change colors with inline scopes.)

\documentclass{standalone}
\usepackage{circuitikz}

\makeatletter
\ctikzset{current arrow color/.initial=black}% create key

\let\old@circ@drawcurrent=\pgf@circ@drawcurrent
\def\pgf@circ@drawcurrent{\old@circ@drawcurrent}

\pgfdeclareshape{currarrow}{
\anchor{center}{
\pgfpointorigin
}
\anchor{tip}{
\pgfpointorigin
    \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by 16
\pgf@x  =\pgf@circ@res@step
}
\behindforegroundpath{      

\pgfscope
    \pgf@circ@res@step = \pgf@circ@Rlen
    \divide \pgf@circ@res@step by 16

    \pgfpathmoveto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{-.8\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{1\pgf@circ@res@step}{0pt}}
    \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{.8\pgf@circ@res@step}}
    \pgfpathlineto{\pgfpoint{-.7\pgf@circ@res@step}{0pt}}           
    \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/current arrow color}}
    \pgfusepath{draw,fill}

\endpgfscope
}
}
\pgfdeclareshape{flowarrow}{
    \anchor{center}{\pgfpointorigin}
    \anchor{tip}{
    \pgfpointorigin
        \pgf@circ@res@step = \pgf@circ@Rlen
            \divide \pgf@circ@res@step by 16
    \pgf@x  =\pgf@circ@res@step
    }
\behindforegroundpath{
    \pgfscope
        \pgf@circ@res@step = \pgf@circ@Rlen
        \divide \pgf@circ@res@step by 4
        \pgfpathmoveto{\pgfpoint{-\pgf@circ@res@step}{0pt}}
        \pgfpathlineto{\pgfpoint{\pgf@circ@res@step}{0pt}}
        %\pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/color}}
  \pgfsetcolor{\pgfkeysvalueof{/tikz/circuitikz/current arrow color}}
        \pgfusepath{draw}
        \pgftransformshift{\pgfpoint{\pgf@circ@res@step}{0pt}}
        \pgfnode{currarrow}{tip}{}{}{\pgfusepath{fill}}
    \endpgfscope
}
}
\makeatother

\begin{document}

\ctikzset{voltage/distance from node=.8}

\begin{circuitikz}[american]
\draw[circuitikz/current arrow color=black]
% bottom line           
   (0,0) to [short, o-] (9,0)
    % shunt branches            
   (2,0) to [C, *-*,l={$C/2$},v=$V_C$,f>^=$I_C(t)$] (2,3)
   (9,0) to [C, *-*,l=$C/2$,n=C2] (9,3)     
    % top line          
   (0,3) to [short,o-] (3,3);
\draw[circuitikz/current arrow color=red] (3,3)
   to [R, l_=$R_1$,i={$\color{red}I_1$},f>^=$\color{red}I_1(t)$] (9,3)
 % Input and output labels
 (C2.s)  node[right] {$V_s$};% anchors rotated
\end{circuitikz}
\end{document}

demo

You must log in to answer this question.

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