我需要與 Circuitikz 內的開關不同的開關。我已經用一些線條繪製了它們,但我想像 Circuitikz 中的其他標準組件一樣使用它們。我只找到了一些向現有組件(如電阻器)添加幾行的教程,但我不知道如何添加完整的新零件。也許你們中的一些人能夠做到這一點?
這是我的工作最小範例:
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[european]{circuitikz}
\begin{document}
\begin{circuitikz}
% Normally Open Switch
\draw[thick] (0,0) --++(0,0.5)--++(-0.4,1) coordinate (sw)
($(sw)+(0.4,0)$) --++(0,0.5);
% Normally Closed Switch
\draw[thick] (3,0) --++(0,0.5)--++(0.4,1) coordinate (sw)
($(sw)+(-0.4,-0.4)$) --++(0,0.9)
($(sw)+(-0.4,-0.4)$) --++(0.4,0);
\end{circuitikz}
\end{document}
結果:
我想得到同樣的結果:
\documentclass{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[european]{circuitikz}
\begin{document}
\begin{circuitikz}
% Normally Open Switch
\draw (0,0) to[nos] (0,2);
% Normally Closed Switch
\draw (3,0) to[ncs] (3,2);
\end{circuitikz}
\end{document}
謝謝你!
答案1
我對 Offner 和 Schliesser 使用了相同的高度、寬度和深度參數。
\documentclass[border=5pt]{standalone}
%\usepackage[utf8]{inputenc}
%\usepackage[T1]{fontenc}
%\usepackage[ngerman]{babel}
\usepackage[european]{circuitikz}
\makeatletter
\ctikzset{bipoles/offner/height/.initial=.35}
\ctikzset{bipoles/offner/width/.initial=.5}
\ctikzset{bipoles/offner/depth/.initial=.1}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/offner/depth}}{nos}{\ctikzvalof{bipoles/offner/height}}{\ctikzvalof{bipoles/offner/width}}{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
\pgfusepath{draw}
}
\def\nospath#1{\pgf@circ@bipole@path{nos}{#1}}
\compattikzset{nos/.style = {\circuitikzbasekey, /tikz/to path=\nospath, l=#1}}
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/offner/height}}{ncs}{\ctikzvalof{bipoles/offner/depth}}{\ctikzvalof{bipoles/offner/width}}{
\pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
\pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfusepath{draw}
\pgfsetlinewidth{\pgfstartlinewidth}
\pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
\pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{0pt}}
\pgfpathlineto{\pgfpoint{.2\pgf@circ@res@right}{\pgf@circ@res@down}}
\pgfusepath{draw}
}
\def\ncspath#1{\pgf@circ@bipole@path{ncs}{#1}}
\compattikzset{ncs/.style = {\circuitikzbasekey, /tikz/to path=\ncspath, l=#1}}
\makeatother
\begin{document}
\begin{circuitikz}
% Normally Open Switch
\draw (0,0) to[nos] (0,2);
% Normally Closed Switch
\draw (3,0) to[ncs] (3,2);
\end{circuitikz}
\end{document}