8

I'm wondering if there are other commands associated with the switch symbol so that one doesn't have to specify if the switch is open or closed. I would like the switch symbol with two connectors and a line rather than the open switch (ospst) and closed switch (cspst). I've looked all over and can't seem to find any solution. Thanks

Caramdir
  • 89,023
  • 26
  • 255
  • 291

1 Answers1

11

The following code is a modification of the definition of cspst. I just removed the arc and the arrow.

\documentclass{minimal}
\usepackage{circuitikz}

% modified code from pgfcircbipoles.sty and circuitikz1.code.tex

\makeatletter
% create the shape
\pgfcircdeclarebipole{}{\ctikzvalof{bipoles/interr/height 2}}{spst}{\ctikzvalof{bipoles/interr/height}}{\ctikzvalof{bipoles/interr/width}}{

    \pgfsetlinewidth{\pgfkeysvalueof{/tikz/circuitikz/bipoles/thickness}\pgfstartlinewidth}

    \pgfpathmoveto{\pgfpoint{\pgf@circ@res@left}{0pt}}
    \pgfpathlineto{\pgfpoint{.6\pgf@circ@res@right}{\pgf@circ@res@up}}
    \pgfusepath{draw}   
}

% make the shape accessible with nice syntax
\def\pgf@circ@spst@path#1{\pgf@circ@bipole@path{spst}{#1}}
\tikzset{switch/.style = {\circuitikzbasekey, /tikz/to path=\pgf@circ@spst@path, l=#1}}
\tikzset{spst/.style = {switch = #1}}
\makeatother

\begin{document}

\begin{circuitikz}
    \draw (0,0) to[switch, l=$t_0$] (2,0)
                to[spst] (2,-2);
\end{circuitikz}

\end{document}

example

Caramdir
  • 89,023
  • 26
  • 255
  • 291
  • Actually if you wouldn't mind helping with one more thing..I noticed that if I try and use to[short, -*] for a connector it disrupts the positioning of the switch itself. Is there a way to have connectors (black dots) at the base of the line where the switch would be connected? It's for an analog electronics report. – Jasper D'Agostino Nov 28 '10 at 23:09
  • @Jasper: I'm not sure what you mean (I have never used circuitikz myself and i'm mostly unfamiliar with circuit diagrams). If it isn't directly connected with drawing a switch without arrow, it is better if you ask a new question. – Caramdir Nov 29 '10 at 01:49
  • @Caramdir, @Jasper: I'm curious, where are these switches (cspst and ospst)? I just looked at the circuit section in the pgfmanual and can't find them. I did find (section 29.4.5) some symbols for contacts which look very similar to what Caramdir's drawn here. – Andrew Stacey Nov 29 '10 at 09:51
  • D'oh. I see. This isn't the circuit tikz library, but is a separate package built on top of tikz. Note that the circuit library in TikZ says: "Inspired by the work of Massimo Redaelli" so the two are closely related. – Andrew Stacey Nov 29 '10 at 09:54
  • The switch without the arrow should be a standard component. – garyp Nov 02 '14 at 15:18