我想绘制一个彩色元素(比如蓝色电容器),但我想将其连接(端点)的颜色保留为黑点。下面给出了所使用的代码,这会导致端点为蓝色,而我希望它们是黑色。如何在 circuitikz 中做到这一点?我将非常感谢您的帮助,因为我一直在寻找但找不到任何帮助。
\begin{document}
\usepackage{circuitikz}
\begin{center}
\begin{circuitikz}
\draw(0,0) to [C,l_=$C$,*-*,color=blue](0,2);
\end{circuitikz}
\end{center}
\end{document}
答案1
好吧,好吧 --- 我不得不承认circuitikz
颜色的管理有很多错误(我刚刚注意到手册中有一个漏洞,我会尝试纠正),但你可以定义一种“始终为黑色”的极点,如下所示:
\documentclass[border=10pt]{standalone}
\usepackage[RPvoltages]{circuitikz}
% this is what the OP asked for
% notice that the manual is buggy
% always black pole styles
\tikzset{bcirc/.style={circ, color=black}}
\ctikzset{b-b/.style = {bipole nodes={bcirc}{bcirc}}}
% for fun
\tikzset{gcirc/.style={circ, color=green},
rsquare/.style={osquarepole, fill=yellow,
% you must use the circuitikz explicitly here
circuitikz/color=blue}}
\ctikzset{c-c/.style = {bipole nodes={gcirc}{rsquare}}}
\begin{document}
\begin{circuitikz}
\draw[](0,0) to [C,l_=$C$, color=blue, b-b] ++ (0,2);
\draw[color=blue](2,0) to [C,l_=$C$, b-b] ++ (0,2);
% for fun
\draw[](4,0) to [C,l_=$C$, color=red, c-c] ++ (0,2);
\end{circuitikz}
\end{document}
结果是:
如果需要取代已建电路中的极点,只需改变标准极点的定义即可:
\documentclass[border=10pt]{standalone}
\usepackage[RPvoltages]{circuitikz}
% this is what the OP asked for
% notice that the manual is buggy
% always black pole styles
\tikzset{bcirc/.style={circ, color=black}}
\ctikzset{*-*/.style = {bipole nodes={bcirc}{bcirc}}}
\ctikzset{-*/.style = {bipole nodes={none}{bcirc}}}
\ctikzset{*-/.style = {bipole nodes={bcirc}{none}}}
\begin{document}
\begin{circuitikz}
\draw[](0,0) to [C,l_=$C$, color=blue, *-*] ++ (0,2);
\draw[color=blue](2,0) to [C,l_=$C$, *-] ++ (0,2);
\draw[](4,0) to [C,l_=$C$, color=red, -*] ++ (0,2);
\end{circuitikz}
\end{document}
答案2
摘自手册第 57 页
应用于电容器
\documentclass{standalone}
\usepackage[american,cuteinductors]{circuitikz}
\usetikzlibrary{shapes,arrows,circuits,calc,babel}
\usepackage{pgfplots}
\tikzset{
% R/.append style={color=red},
C/.append style={color=blue},
% battery1/.append style={color=green},
}
\begin{document}
\begin{tikzpicture}[transform shape, scale=1.0,thick]
\draw (0,0)node[circ]{} to [C = $C$] (0,2)node[circ]{};
\end{tikzpicture}
\end{document}
答案3
您可以在绘制极点的代码中添加颜色设置。这在pgfcircbipoles.tex
命令中的文件中定义\drawpoles
。可以使用包动态更改此代码,该包提供对命令执行搜索和替换操作的xpatch
命令。\xpatchcmd
在下面的 MWE 中,修改后的命令\drawpoles
使用新的颜色命令\polecolor
,可以在文档中更改。请注意,\draw
如果需要在电路中更改颜色,则需要启动新命令。
梅威瑟:
\documentclass{article}
\usepackage{circuitikz}
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\drawpoles}{(\tikztostart) node[\pgf@circ@temp]}{(\tikztostart) node[\pgf@circ@temp,color=\polecolor]}{}{}
\xpatchcmd{\drawpoles}{(\tikztotarget) node[\pgf@circ@temp]}{(\tikztotarget) node[\pgf@circ@temp,color=\polecolor]}{}{}
\def\polecolor{black}
\makeatother
\begin{document}
\begin{center}
\begin{circuitikz}
\draw(0,0) to [capacitor,l_=$C$,*-*,color=blue](0,2);
\def\polecolor{green}
\draw(0,0) -- (2,0) to [capacitor,l_=$C$,*-*,color=blue](2,2) -- (0,2);
\end{circuitikz}
\end{center}
\end{document}
结果:
对于旧版本circuitikz
(0.9.1 之前),补丁如下:
\xpatchcmd{\drawpoles}{(\tikztostart) node[circ]}{(\tikztostart) node[circ,color=\polecolor]}{}{}
\xpatchcmd{\drawpoles}{(\tikztotarget) node[circ]}{(\tikztotarget) node[circ,color=\polecolor]}{}{}