circuitikz 中的新开关(否,nc)

circuitikz 中的新开关(否,nc)

我需要与 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}

演示

相关内容