# How could I insert a switch symbol with tikzpicture?

I am working on a project and I'm trying to implement this block diagram with tikzpicture (please ignore the Greek letters and the surrounding box in the middle):

I have managed to approximate this picture in tikzpicture with the following code:

### tikzstyle:

\tikzstyle{block} = [draw, fill=white!20, rectangle,
minimum height=1.5em, minimum width=1.5*1.86em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]


### tikzpicture:

\begin{tikzpicture}[auto, node distance=1.5cm, >=latex']
\node [input, name=input]{$r=0$};
\node [sum, right of=input](sum1){};
\node [coordinate, right of=sum1](test2){};
\node [block, right of=test2](a){a};
\node [sum, right of=a](sum2){};
\node [block, right of=sum2](dint){$\frac{1}{s^2}$};
\node [block, below of=a](b){b};
\node [coordinate, below of=b](test){};
\node [output, right of=dint](output){qq};
\draw [->] (input) -- node{$r$} node[pos=0.99]{$+$} (sum1);
\draw [->] (sum1) -- node{} (a);
\draw [->] (a) -- node[pos=0.99]{$+$} (sum2);
\draw [->] (test2) |- (b) -|   node[pos=0.99]{$+$}(sum2);
\draw [->] (sum2) -- node{} (dint);
\draw [->] (dint) -- node[name=y]{$y$} (output);
\draw [->] (y) |- (test) -| node[pos=0.99] {$-$}  (sum1);
\end{tikzpicture}


Which produces the following result:

However, I have found no way to insert a switch symbol. Is there a predefined symbol in tikzpicture (although I cannot find it)? If not, could the problem be solved in an other way?

• See questions tex.stackexchange.com/questions/276244/…. Package circuitikz define three (four with push button) kind of switches. See package manual on page 17: \draw (...) to[cspst] (...), \draw (...) to[spst] (...) and \draw (...) to[ospst] (...). Please add preamble with used packages, definitions of nodes etc to your MWE. – Zarko Nov 3 '15 at 0:09

Here is a possible way to do it:

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}

\usetikzlibrary{circuits.ee.IEC}

\begin{document}

\begin{tikzpicture}[circuit ee IEC, font=\sffamily\footnotesize]

\draw (0,0) to [make contact={info={S$\mathsf{_{1a}}$},info'={make contact$\mathsf{_{}}$}}] (2,0);

\draw (3,0) to  [break contact={info={S$\mathsf{_{1a}}$}, info'={break contact$\mathsf{_{}}$}}] (5,0);

\draw[set make contact graphic = var make contact IEC graphic] (0,-2) to [make contact={info ={S$\mathsf{_{1a}}$}, info'={var make contact}}] (2,-2);

\end{tikzpicture}

\end{document}


This was taken from the german site Matroids Matheplanet. Here is the output:

Hope it helps!

• Thanks for the answer. I had already solved the problem by the time you posted this answer and I have just posted it as an answer here. I'll definitely study your solution too for further notice. +1 – codingEnthusiast Nov 3 '15 at 13:24

I've managed to finally solve this using an additional package called circuitikz, so I've combined one of its elements to my existing tikzpicture image:

\usepackage{circuitikz}


### tikzstyle (minor modifications):

\tikzstyle{block} = [draw, fill=red!20, rectangle,
minimum height=1.5em, minimum width=1.5*1.80em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]


### tikzpicture (please excuse the names of the elements):

\begin{tikzpicture}[auto, node distance=2cm, >=latex']
\node [input, name=input]{$r=0$};
\node [sum, right of=input](sum1){};
\node [coordinate, right of=sum1](test2){};
\node [block, right of=test2](a){a};
\node [coordinate, right of=a](test4){};
\node [sum, right of=test4](sum2){};
\node [block, right of=sum2](dint){\large $\frac{1}{s^2}$};
\node [block, below of=a](b){b};
\node [coordinate, right of=b](test5){};
\node [coordinate, below of=sum2](test3){};
\node [coordinate, below of=b](test){};
\node [coordinate, right of=a](test4){};
\node [output, right of=dint](output){qq};
\draw [->] (input) -- node{$r$} node[pos=0.99]{$+$} (sum1);
\draw [->] (sum1) -- node{} (a);
\draw [->] (a) -- node[pos=0.99]{$+$} (sum2);
\draw [->] (test2) |- (b);
\draw [-] (b) -- (test5);
\draw [-] (test5) to[cspst] (test3);
\draw [->] (test3) -- node[pos=0.9]{$+$} (sum2);
\draw [->] (sum2) -- node{} (dint);
\draw [->] (dint) -- node[name=y]{$y$} (output);
\draw [->] (y) |- (test) -| node[pos=0.99] {$-$}  (sum1);
\end{tikzpicture}


The job is done by this command:

\draw [-] (test5) to[cspst] (test3);


I've defined two coordinate elements:

1. test5 which is to the left of the switch.
2. test3 which is to the right of the switch.

By using to[cpspst] a switch is drawn between those two invisible elements, so the rest of the task can be completed easily through commands already used by the question's tikzpicture. This produces this image: