我想繪製一個彩色元素(例如藍色電容器),但我想將其連接(端點)的顏色保留為黑點。下面給出了所使用的程式碼,其結果是端點為藍色,而我希望它們為黑色。在 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]}{}{}