1

I've been trying to do my homework assignments with LaTeX so my terrible drawing skills don't cause me to lose points, however some of the drawings I need to produce have an SPDT switch that is oriented vertically. The attached image is an example of what I'm trying to create, but I can't seem to get the switch oriented properly. I can recreate the entire circuit otherwise.

The dotted line to position B is not a requirement for my use. I've looked through the documentation but I couldn't find anything about rotating the switch.

I'm relatively unfamiliar with TikZ drawing, however I can use it at a basic level.

Rotated SPDT switch example

2
  • Think about it as three points. Connect two of them and leave the horizontal.
    – CroCo
    Commented Nov 30, 2016 at 12:52
  • 1
    node[spdt,rotate=90] if you don't mind the leads being vertical. The anchors are in, out 1 and out 2. Commented Nov 30, 2016 at 14:02

5 Answers 5

3

Switch is nothing but lines and a curve. In the following picture, a simple switch is drawn

enter image description here

\documentclass[border={10}]{standalone}


\usepackage{circuitikz}

\begin{document}

\begin{circuitikz} 
\draw (3.5,4) -- (4,3.5);
\draw (4.5,4) to[R,-o] (8.5,4);
\draw (4,3.5) to[short,-o] (4.5,4);
\draw (4,0) to[short,-*]   (4,3.5);
\draw[->,thick] (3.5,3.7)  to[out=45,in=135]   (4.5,3.7);
\draw (0,0) to[battery] (0,4)  to[R,-o] (3.5,4);

\end{circuitikz}

\end{document}
3

Another possibility, instead of using manual shifts, you can do the following with a recent circuitikz (notice that the result is more or less the same as @Archange's nice answer) --- the code is heavily commented to explain what I am doing there.

\documentclass[tikz,border=3.14]{standalone}
\usepackage[siunitx, american, RPvoltages]{circuitikz}

\begin{document}
\begin{tikzpicture}[]
    \ctikzset{voltage=raised}
    %%
    %% let's start with the capacitor --- you'll know why shortly
    %%
    \draw (0,0) coordinate(bot) to[C=\SI{1}{\uF}, v>=$v(t)$, *-] ++(0,2)
    %%
    %% now we position the switch. I am positioning it on the
    %% single throw because it is the only one with the straight
    %% connection to the pole:
    %%
        node[cute spdt up arrow,rotate=90,anchor=in] (S){}
        (S.center) node[above=1ex, font=\tiny, scale=0.8]{$t=0$};
    %%
    %% let's do the left side. The trick to have the wire going
    %% out at the correct angle is to use the internal node for
    %% the pole. When you use a node instead of a coordinate, TikZ
    %% (and circuitikz after 1.2.1) uses the border anchor
    %%
    \draw (S-out 1) to[R, l_=\SI{200}{\ohm}] ++(-3,0) coordinate(left)
    %%
    %% mark the coordinate where we are to use it with
    %% the perpendicular coordinate system; now you can just change
    %% the ++(3,0) above to enlarge or tighten the circuit and the
    %% rest will follow!.
    %%
        to[V, invert] (left|-bot) -- (0,0);
    %%
    %% let go for the right side
    %%
    \draw (S-out 2) to[R, l^=\SI{400}{\ohm}, -*] ++(3,0) coordinate(right);
    %%
    %% Finally, draw a line to the same horizontal end...
    %%
    \draw (bot) -- (bot-|right);
    %%
    %% and if you really like it, the dashed line... using the internal
    %% nodes again
    %%
    \draw [densely dashed] (S-in) -- (S-out 2);
\end{tikzpicture}
\end{document}

enter image description here

Notice that the full circuit is just 8-9 lines...

2
  • 1
    Awesome, I did not know about internal nodes. Now I’ll have to update several codes using shiftings. ^^
    – Archange
    Commented Oct 2, 2021 at 16:45
  • Yep, I added it to cute switches and other shapes --- the problem was that they were not useful until I fixed the node/coordinate bug in 1.2.1 (you can see a longer comment in the manual, in 1.9 "incompatibility between versions").
    – Rmano
    Commented Oct 2, 2021 at 16:50
2

Here is another solution using "rotate" to place the "spdt" vertically :

\documentclass[border=5pt]{standalone}

\usepackage[siunitx,european,straightvoltages]{circuitikz}

\begin{document}

\begin{circuitikz}
\draw
(3,3) node[cute spdt up arrow, rotate = 90] (Sw){}
(3,0)to[C=\SI{4}{\micro\farad}, v=$v_1(t)$,*-](Sw.in)
(0,0)to[V=\SI{100}{\volt}](0,3)
(0,3)|-(Sw.out 1)
(Sw.out 2)-|(6,3)
(0,0)--(6,0)
(6,3)to[C, l_=\SI{1}{\micro\farad}, v^<=$v_2(t)$](6,0)
; 
\draw (3,4)node{B};
\draw (3,3.6)node[ocirc]{};
\draw (2.4,3.6)node{A};
\draw (3.5,3.6)node{C};
\end{circuitikz}    

\end{document}

And its output :

enter image description here

1

As other suggested, you can use [rotate=90] to achieve this. But in contrary to what they say/show, you can have the wires on the left and right part of the outs.

Here is a code producing as closed as I could reasonably get from your picture:

\documentclass{standalone}

\usepackage[american,RPvoltages,siunitx]{circuitikz}

\begin{document}
    \begin{tikzpicture}
        % Switch
        \draw (3,2.5) node[cute spdt up arrow,rotate=90] (S) {};
        \draw ([yshift=7]S) node [scale=0.5] {$t=0$};
        \node at ([yshift=7]S.cout 1) [scale=.75] {A};
        \node at ([yshift=7]S.cout 2) [scale=.75] {B};
        \draw [densely dashed] ([xshift=1,yshift=1]S.cin) -- ([xshift=-1,yshift=-1]S.cout 2); % Optional dashed line
        % Left part
        \draw (S.in) to [C, l_=1<\micro\farad>, name=C] (3,0)
                     to [short] (0,0)
                     to [V] (0,0 |- S.cout 1) % Using "S.cout 1" y coordinate
                     to [R=200<\ohm>] ([xshift=-1.5]S.cout 1); % Compensating for node size
        % Right part
        \draw (3,0) to [short] (6,0);
        \draw ([xshift=1.5]S.cout 2) to [R=4<\kilo\ohm>] (6,0 |- S.cout 2); % Using "S.cout 1" y coordinate and compensating for node size
        % Capacitor voltage
        \node at (C.north west) [above right] {$+$};
        \node at (C.north) [right] {$v(t)$};
        \node at (C.north east) [below right] {$-$};
        % Filled nodes
        \fill (3,0) circle(.05);
        \fill (6,0 |- S.cout 2) circle(.05);
    \end{tikzpicture}
\end{document}

And the result: Generated circuit

1
  • 1
    Nice, +1, but you will be much more efficient using the internal nodes of the switch and relying on TikZ feature of connecting the borders when a coordinate is really a node. I added an example!
    – Rmano
    Commented Oct 2, 2021 at 16:41
0

Here is another option:

\documentclass[border=5pt]{standalone}

\usepackage[american voltages,siunitx]{circuitikz}

\begin{document}
    \begin{tikzpicture}[x=3.5cm, y=3.5cm] 
        % Vertices
        \coordinate [label=above left:\textcolor{blue}{}] (A) at (0.0, 0.8);
        \coordinate [label=above:\textcolor{blue}{}] (B) at (0.8, 0.8);
        \coordinate [label=below:\textcolor{blue}{}] (C) at (1.6, 0.8);
        \coordinate [label=below:\textcolor{blue}{}] (D) at (0.8, 0.0);
        \coordinate [label=below:\textcolor{blue}{}] (E) at (0.0, 0.0);
        \coordinate [label=below:\textcolor{blue}{}] (F) at (1.6, 0.0);
        % Circuit elements
        \draw (A) to [V, l_=$V_s$] (E) to (D);
        \draw (A) to [R,l=$R_s$] ($(B)+(-0.15,0.0)$)node[ocirc]{};
        \draw (D) to [C,l=$C$] ($(B)+(0.0,-0.2)$) node[circ]{};
        \draw (D) to (F) to [R,l_=$R$] (C) to ($(B)+(0.15,0.0)$) node[above right]{B}node[ocirc]{};
        % capacitor voltage
        \draw ($(B)+(0.24, -0.35)$) node[]{$+$};
        \draw ($(B)+(0.24, -0.5)$) node[]{$v(t)$};
        \draw ($(B)+(0.24, -0.65)$) node[]{$-$};
        % Switch
        \draw ($(B)+(0.0, -0.2)$) to ($(B)+(-0.15, 0.03)$) node[above left]{A} node[above right]{$t\text{=}0$};
        \draw[dashed] ($(B)+(0.0, -0.2)$) to ($(B)+(0.15, 0.03)$);
        \draw[-latex',brown!50!black,thick] ($(B)+(-0.15, -0.15)$) to [out=45,in=135] ($(B)+(0.15, -0.15)$);
        % Filled Node
        \fill (D) circle(2pt);
    \end{tikzpicture}
\end{document}

and its output: enter image description here

You must log in to answer this question.

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