![如何更改 circuitikz 中某些元件标签的颜色?](https://linux22.com/image/384342/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%20circuitikz%20%E4%B8%AD%E6%9F%90%E4%BA%9B%E5%85%83%E4%BB%B6%E6%A0%87%E7%AD%BE%E7%9A%84%E9%A2%9C%E8%89%B2%EF%BC%9F.png)
我尝试查看这些先前的帖子来解决我的问题:
这些帖子提出的解决方案似乎重新编程了图中所有电流的颜色。我试图做的是选择性地改变图表上电流箭头的颜色。在下面的网络中,我试图将整个 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}