[Tex/LaTex] Circuitikz – Change current arrow color AND label color at once

circuitikztikz-pgf

i found this post fixing one of my two problems:
circuittikz colored current arrows
It redefines the color of the current arrows.
What I also want to have is the label of the current being written in the same color.
Is there a (easy) way to manage this?

Thank you in advance.

Best Answer

It turns out the old solution no longer works, so I revised it. Also, one can simply use \color{red} (for example) in any text field, or [color=red] in a draw command to change the text color.

\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-o] (11,0)
% shunt branches            
    (2,0) to [C, *-*,l={$C/2$},v=$V_C$] (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$,i={\color{\pgfkeysvalueof{/tikz/circuitikz/current arrow color}}$I_1$}] (5,3)
    (5,3)  -- (6,3)
    to [L, l_=$L$] (8,3)
    to [short,-o] (11,3)
% Input and output labels
    (C2.s)  node[right] {$V_s$};% anchors rotated
\draw[<->,color=red] (11,0.2) -- (11,2.8) node[midway,fill=white] {$V_r$};
\end{circuitikz}
\end{document}

demo