5

I am drawing a circuit with circuitikz that have lots of SPDT switches. I want to show the circuit at two different moments: once, when all the SPDT switches connected to out1 and the second with all of them to out2. Is there any simple way to do this?

Here is a working example of what I am trying to code:

\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}


\begin{circuitikz}
    % Switches
    \draw (0,2) node[spdt,xscale=1,anchor=in] (Swp) {};
    \draw (0,0) node[spdt,xscale=-1,anchor=in] (Swc) {};
    \draw (0,-2) node[spdt,xscale=1,anchor=in] (Swn) {};

    % Capacitors
    \draw (Swp.in) to[C,l_=$(C_s + \Delta C)$] (Swc.in);
    \draw (Swn.in) to[C,l^=$(C_s - \Delta C)$] (Swc.in);

    % Voltages
    \draw (Swp.out 1) node[anchor=west] {$V_{in}^+$};
    \draw (Swn.out 1) node[anchor=west] {$V_{in}^-$};
    \draw (Swp.out 2) node[anchor=west] {$V_{cm}$};
    \draw (Swn.out 2) node[anchor=west] {$V_{cm}$};
    \draw (Swc.out 1) node[anchor=east] {$V_{cm}$};
    \draw (Swc.out 2) node[anchor=east] {$V_{ref}$};
\end{circuitikz}
\end{document}
6

Turn the appropriate values into a parameter-dependant values and use a conditional test:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{circuitikz}

\def\mycircuit{%
    % Switches
    \draw (0,2) node[spdt,xscale=1,yscale=\value,anchor=in] (Swp) {};
    \draw (0,0) node[spdt,xscale=-1,yscale=\value,anchor=in] (Swc) {};
    \draw (0,-2) node[spdt,xscale=1,yscale=\value,anchor=in] (Swn) {};

    % Capacitors
    \draw (Swp.in) to[C,l_=$(C_s + \Delta C)$] (Swc.in);
    \draw (Swn.in) to[C,l^=$(C_s - \Delta C)$] (Swc.in);

    % Voltages
    \draw (Swp.out \myone) node[anchor=west] {$V_{in}^+$};
    \draw (Swn.out \myone) node[anchor=west] {$V_{in}^-$};
    \draw (Swp.out \mytwo) node[anchor=west] {$V_{cm}$};
    \draw (Swn.out \mytwo) node[anchor=west] {$V_{cm}$};
    \draw (Swc.out \myone) node[anchor=east] {$V_{cm}$};
    \draw (Swc.out \mytwo) node[anchor=east] {$V_{ref}$};
}

\newcommand\swapot[1]{%
\ifnum#1=1\relax
  \def\value{1}
  \def\myone{2}\def\mytwo{1}
\else
\ifnum#1=-1\relax
  \def\value{-1}
  \def\myone{1}\def\mytwo{2}
\fi\fi%
}
\begin{document}

\begin{circuitikz}
\swapot{1}
\mycircuit
\begin{scope}[xshift=5cm]
\swapot{-1}
\mycircuit
\end{scope}
\end{circuitikz}

\end{document}

enter image description here

  • Nice solution. I'd rather use 1 for identity and -1 for a change; but \relax, not a space, is a variant I should choose from time to time. – Przemysław Scherwentke May 11 '13 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.