Circuitikz - 立即更改当前箭头颜色和标签颜色

Circuitikz - 立即更改当前箭头颜色和标签颜色

我发现这篇文章解决了我的两个问题之一: circuittikz 彩色电流箭头 它重新定义了电流箭头的颜色。我还想让电流标签也用相同的颜色书写。有没有(简单的)方法来管理这个?

先感谢您。

答案1

事实证明旧解决方案不再有效,所以我修改了它。此外,只需\color{red}在任何文本字段或绘制命令中使用(例如)即可[color=red]更改文本颜色。

\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}

演示

相关内容