Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
For some reason, your picture doesn't appear properly on the page. Am I the only one experiencing a problem? I uploaded a cropped version of it; now everything is fine. –  Jubobs Jan 18 at 6:55

4 Answers 4

up vote 9 down vote accepted

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}
share|improve this answer
    
Jubobs, I tried to use your commands in a \documentclass[paper=a4,fontsize=12pt,convert = false]{article}, but I have problems with this command to[open,v^>=$v_1(t)$,o-o], in specific with "^". Could you help me? If you need any information, you can ask me. –  xiuhays Aug 23 at 0:50

If PSTricks is allowed, you can do the following:

\documentclass{article}

% PSTricks.
\usepackage{
  pst-circ,
  pst-bspline,
  pstricks-add
}
\psset{unit = 0.8}

% Width and height of the diagram.
\def\width{12 }
\def\height{6 }

% Calculating width and height of picture.
\usepackage{expl3}
\ExplSyntaxOn
  \cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
\newcommand*\Width{\calc{\width+0.4}}
\newcommand*\Height{\calc{\height+0.82}}

\begin{document}

% Drawing.
\begin{pspicture}(-0.4,-0.05)(\Width,\Height)
  % Coordinates for the ends of the wires.
  \pnodes{P}%
    (0,0)(0,0)% Doubled to let the nodes start from P1 instead of P0.
    (!0.7 \width mul 0)%
    (\width,0)%
    (0,\height)%
    (!0.35 \width mul \height)%
    (!0.7  \width mul \height)
    (\width,\height)
  % Wires and components.
  \wire[arrows = o-o](P1)(P3)
  \coil[arrows = o-](P4)(P5){$L$}
  \resistor[arrows = -o, dipolestyle = zigzag](P5)(P6){$R$}
  \wire[arrows = o-o](P6)(P7)
  \capacitor[arrows = *-*](P2)(P6){$C$}
  % Labels.
  \uput[90](P1){$-$}
  \uput[90](P3){$-$}
  \uput[270](P4){$+$}
  \uput[270](P7){$+$}
 {\psset{linestyle = none}
  \pcline(P1)(P4)
  \ncput*{$v_1(t)$}
  \pcline(P3)(P7)
  \ncput*{$v_2(t)$}}
  % Direction of the current.
  \psBspline[arrows = ->]%
       (!0.7 \width mul 3   sub \height 1 sub)%
       (!0.7 \width mul 1.2 sub \height 1 sub)%
       (!0.7 \width mul 1.2 sub 1)%
       (!0.7 \width mul 3   sub 1)
  \rput(!0.7 \width mul 2.2 sub \height 2 div){$i(t)$}
\end{pspicture}

\end{document}

output

Here, pst-circ is for drawing the electrical components, pst-bspline is for drawing the curved arrow, and pstricks-add is for setting the labels.

Width and height of the diagram can be chosen freely, and calculation of the corresponding width and height of the picture is automated.

Note: The advantage of using Herbert Voß' package pst-circ for a drawing like this is that all the macros are (more or less) self-explanatory, so the code is really easy to edit if needed. Also, the documentation has a lot of examples.

share|improve this answer
1  
+1 for PSTricks. I believe that your code can still be simplified. I am doing it... –  Who is crazy first Jan 18 at 7:21
1  
+1 Pretty nice. –  Jubobs Jan 18 at 7:41

This is how. Define (x,y) coordinate for each circuit node (2cm separation is fairly good in general), then use to[options] to connect all of the nodes, where options can be R, L, C, open (circuit), short (circuit), l(abel)=, v=, i=, for label/current/voltage name respectively. Variants such as v^, v_ and equivalents are designed to put labels on either side of circuit elements. As to the current loop for KVL, this solution uses amssymb package with node technique to achieve that. By default, currents are labeled on each branch as shown in the capacitor branch.

enter image description here

Code:

\documentclass[convert = false, border=10pt,]{standalone}
\usepackage[american,siunitx]{circuitikz}
\usepackage{latexsym,amssymb,amsmath}
\begin{document}
\begin{circuitikz}
\draw (-.5, 2) to[L, l = $L$] (2, 2) to [R, l = $R$] (4, 2) to [short](6,2)
(4,2) to[C,l=$C$] (4,0)
(-0.5,2) to [open, v=$v_1(t)$,o-o](-0.5,0)
(6,2) to [open, v=$v_2(t)$,o-o] (6,0)   % use v^=$V_2$, if you want it on the right side.
(-0.5,0)--(6,0)
(1.5,1) node[scale=3]{$\circlearrowright$}
(1.5,1) node{$i_1$};
\end{circuitikz}
\end{document}
share|improve this answer

Just another solution with PSTricks.

\documentclass[pstricks,12pt]{standalone}
\usepackage{pst-circ}
\def\Tension(#1)(#2)#3{\uput[-90](#1){$+$}\uput[90](#2){$-$}\rput([nodesep=1.5]{#2}#1){#3}}
\begin{document}
\begin{pspicture}(-1,1)(9,-4)
    \pnodes(0,0){A}(3,0){B}(6,0){C}(8,0){D}([offset=-3]A){A'}([offset=-3]B){B'}([offset=-3]C){C'}([offset=-3]D){D'}
    \coil[arrows=o-,labeloffset=20pt](A)(B){$L$}
    \resistor[dipolestyle=zigzag,labeloffset=18pt](B)(C){$R$}
    \wire[arrows=-o](C)(D)
    \capacitor[arrows=*-*,labeloffset=-24pt](C)(C'){$C$}
    \wire[arrows=o-o](A')(D')
    \Tension(A)(A'){$v_1(t)$}
    \Tension(D)(D'){$v_2(t)$}
    \pcbar[linearc=20pt,arm=50pt]{->}([offset=-20pt]B)([offset=20pt]B')
    \nbput[labelsep=12pt]{$i(t)$}
\end{pspicture}
\end{document}

enter image description here

Notes

    % \the following tensions don't work temporarily
    %\tension[tensionstyle=pm](A)(A'){$v_1(t)$}
    %\tension[tensionstyle=pm](D)(D'){$v_2(t)$}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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