2

I was looking for a normally closed switch in circuitikz, but with a closing or opening arrow. Since I couldn't find them, I coded them myself. It's mostly a copy-paste of the normally closed switch and the opening spst/closing spst. Note that the symbols are slightly wider than the normally closed switch which is implemented at the moment.

\documentclass{standalone}
\usepackage{tikz}
\usepackage{circuitikz}


\ctikzset{bipoles/oncs/height/.initial=.35}
\ctikzset{bipoles/oncs/width/.initial=.45}
\ctikzset{bipoles/oncs/depth/.initial=.2}

\makeatletter

%% Opening NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{oncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-10}{1.2\pgf@circ@res@right}}
        \pgfpatharc{-10}{90}{1.2\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{cncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}
    \pgfsetlinewidth{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{0pt}}
    \pgfpathlineto{\pgfpoint{.45\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{1.2\pgf@circ@res@right}}
        \pgfpatharc{90}{-20}{1.2\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

\pgfcirc@activate@bipole@simple{l}{oncs}
\pgfcirc@style@to@style{oncs}{opening normal closed switch}
\pgfcirc@activate@bipole@simple{l}{cncs}
\pgfcirc@style@to@style{cncs}{closing normal closed switch}

\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,2) to[ncs] (1,2) node[anchor = west] {normally closed switch};
    \draw (0,1) to[cncs] (1,1) node[anchor = west] {closing normally closed switch};
    \draw (0,0) to[oncs] (1,0) node[anchor = west] {opening normally closed switch};
\end{tikzpicture}
\end{document}

enter image description here

3
  • You can make a PR on github.com/circuitikz/circuitikz, and I'll add the symbols to the package. But they should match the existing ones...
    – Rmano
    Commented Aug 14, 2023 at 11:28
  • yeah, I tried, but the arrow starts on the vertical line, when I use the existing arrow in combination with the existing normally open switch. That really doesn't look good.
    – DraUX
    Commented Aug 14, 2023 at 11:36
  • 1
    I opened an issue here: github.com/circuitikz/circuitikz/issues/733
    – Rmano
    Commented Aug 15, 2023 at 14:35

1 Answer 1

1

I would advocate to let the size of the switch as it is (basically for backward compatibility) and use a slightly smaller arc:

\documentclass[border=2.78mm]{standalone}
\usepackage{tikz}
\usepackage{circuitikz}


\ctikzset{bipoles/oncs/height/.initial=.35}
\ctikzset{bipoles/oncs/width/.initial=.35}
\ctikzset{bipoles/oncs/depth/.initial=.2}

\makeatletter

%% Opening NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{oncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \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@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{-20}{.9\pgf@circ@res@right}}
        \pgfpatharc{-10}{90}{.9\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

%% Closing NCS
\pgfcircdeclarebipolescaled{switches}
{}
{\ctikzvalof{bipoles/oncs/depth}}
{cncs}
{\ctikzvalof{bipoles/oncs/height}}
{\ctikzvalof{bipoles/oncs/width}}
{
    
    \pgf@circ@setlinewidth{bipoles}{\pgfstartlinewidth}
    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.9\pgf@circ@res@right}{\pgf@circ@res@up}}
    \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@up}}
    \pgfusepath{draw}

    \pgfscope
        \pgftransformshift{\pgfpoint{\pgf@circ@res@left}{0pt}}
        \pgfpathmoveto{\pgfpointpolar{90}{.9\pgf@circ@res@right}}
        \pgfpatharc{90}{-35}{.9\pgf@circ@res@right}
        \pgfcirc@set@arrows{switch}{}{latexslim}
        \pgfsetbeveljoin
        \pgfusepath{draw}
    \endpgfscope
}

\pgfcirc@activate@bipole@simple{l}{oncs}
\pgfcirc@style@to@style{oncs}{opening normal closed switch}
\pgfcirc@activate@bipole@simple{l}{cncs}
\pgfcirc@style@to@style{cncs}{closing normal closed switch}

\makeatother

\begin{document}
\begin{tikzpicture}
    \draw (0,2) to[ncs] (1,2) node[anchor = west] {normally closed switch};
    \draw (0,1) to[cncs] (1,1) node[anchor = west] {closing normally closed switch};
    \draw (0,0) to[oncs] (1,0) node[anchor = west] {opening normally closed switch};
\end{tikzpicture}
\end{document}

enter image description here

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .