[Tex/LaTex] Drawing electrical diagram using circuitikz

circuitikz

I looked at the documentation and examples on CTAN, but circuitikz is hard to get the hang of.

I am trying to create

wanted

Here is what I have so far:

\documentclass[convert = false]{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
  \draw (-.5, 0) to[L, l = L] (1.4, 0)
           to[R, l = R] (5, 0);
\end{circuitikz}
\end{document}

but the spacing is weird, and I can't seem to figure out how to set it up.

Best Answer

I too find the circuitikz documentation a bit lacking, but you learn a lot from inspecting the examples. A quick [circuitikz] search on the site will lead you to more examples. Moreover, a few additional circuitikz examples are available at texample.net.

Regarding spacing, my main piece of advice (which applies to any vector-graphics package, really) is to parameterise everything at the beginnning; refrain from using "magic numbers". Your circuit will be far easier to adjust; moving things around will be a breeze. See below.

enter image description here

\documentclass[convert = false]{article}
\usepackage[american]{circuitikz}
\begin{document}
\begin{circuitikz}[scale=2]
    \def\xPortLeft{0}
    \def\yTerminalBottom{0}
    \def\yL{1.5}
    \def\xL{1}
    \def\xR{1.75}
    \def\xC{2.25}
    \def\xPortRight{3}
    % left loop
    \draw                               (\xPortLeft,\yL)
            to[L=$L$, o-]               (\xL, \yL)
            to[R=$R$]                   (\xR, \yL)
            to[short]                   (\xC,\yL)
            to[C, l_=$C$,*-*]           (\xC,\yTerminalBottom)
            to[short,i=$i(t)$]          (\xPortLeft,\yTerminalBottom)
            to[open,v^>=$v_1(t)$,o-o]   (\xPortLeft,\yL);
    % right branch
    \draw                               (\xC,\yL)
            to[short]                   (\xPortRight,\yL)
            to[open,v^=$v_2(t)$,o-o]    (\xPortRight,\yTerminalBottom)
            to[short]                   (\xC,\yTerminalBottom);
\end{circuitikz}
\end{document}
Related Question