我尝试查看这些先前的帖子来解决我的问题:
这些帖子提出的解决方案似乎重新编程了图中所有电流的颜色。我试图做的是选择性地改变图表上电流箭头的颜色。在下面的网络中,我试图将整个 I1(t) 箭头涂成红色(在我的 MWE 中,不仅仅是箭头尖端被涂成颜色),并将 Ic(t) 保留为黑色,包括箭头尖端。
\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
这也会修改flowarrow
形状,并将图表拆分为两个图。(如果我没记错的话,您无法使用内联范围更改颜色。)
\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}