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.

Making some electric circuits in tikz for the very first time, and need to replicate the following image

enter image description here

Not a very complicated circuit. Now here is what I have done so far

enter image description here

\documentclass[10pt,a4paper]{minimal}
\usepackage{tikz}
\usetikzlibrary{circuits}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac source}
\tikzset{set ac source graphic = ac source IEC graphic}
\tikzset{
         ac source IEC graphic/.style=
          {
           transform shape,
           circuit symbol lines,
           circuit symbol size = width 3 height 3,
           shape=generic circle IEC,
           /pgf/generic circle IEC/before background=
            {
             \pgfpathmoveto{\pgfpoint{-0.8pt}{0pt}}
             \pgfpathsine{\pgfpoint{0.4pt}{0.4pt}}
             \pgfpathcosine{\pgfpoint{0.4pt}{-0.4pt}}
             \pgfpathsine{\pgfpoint{0.4pt}{-0.4pt}}
             \pgfpathcosine{\pgfpoint{0.4pt}{0.4pt}}
             \pgfusepathqstroke
            }
          }
        }
\begin{document}

\begin{tikzpicture}[circuit ee IEC]
  \draw (0,0) to [capacitor={info={$q$\ \ $-q$}}]     ++(1, 0)
              to [resistor={info ={$R$}}]             ++(2, 0) 
              to [current direction' = {info = {$I$}}]++(0,-2) 
              to [inductor={info=$L$}]                  (0,-2)  
              to [ac source={info={$V$}}]               (0,0);
\end{tikzpicture}

\end{document}

I have no idea what I have done so far, I just randomly copied examples from the internet. The nodes is a mess, as I just kept trying until they all connected. What does the ++ mean? And could someone help me understand how to fix my circuit diagram to resemble the image above? =)

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

My solution leads to:

enter image description here

Code:

\documentclass[10pt,a4paper]{minimal}
\usepackage{tikz}
\usetikzlibrary{circuits}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac source}
\tikzset{set ac source graphic = ac source IEC graphic}
\tikzset{
         ac source IEC graphic/.style=
          {
           transform shape,
           circuit symbol lines,
           circuit symbol size = width 3 height 3,
           shape=generic circle IEC,
           /pgf/generic circle IEC/before background=
            {
             \pgftransformrotate{90}
             \pgfpathmoveto{\pgfpoint{-0.575pt}{0pt}}
             \pgfpathsine{\pgfpoint{0.3pt}{0.3pt}}
             \pgfpathcosine{\pgfpoint{0.3pt}{-0.3pt}}
             \pgfpathsine{\pgfpoint{0.3pt}{-0.3pt}}
             \pgfpathcosine{\pgfpoint{0.3pt}{0.3pt}}
             \pgfusepathqstroke
            }
          }
        }
\begin{document}
\scalebox{1.5}{
\begin{tikzpicture}[circuit ee IEC]
  \draw (0,0) to [capacitor={info'={$C$}}]     ++(1.5, 0)
              to [resistor={info'={$R$}}]             ++(2.5, 0) 
              to [current direction = {info' = {$I$}}]++(0,-3) 
              to [inductor={info'=$L$}]                  (0,-3)  
              to [ac source={info={$V$}}]               (0,0);

\node[above right] at (0.75,0){$-q$};        
\node[above left] at (0.75,0){$q$ \ };   
\end{tikzpicture}
}
\end{document}

From the starting point (0,0), all elements are displayed in sequence. For example, the capacitor is placed from the starting point until coordinate (1.5,0) (that's the meaning behind ++). It is possible to display information with the key info or info'; in general the ' allows you to invert the positioning of a label or the direction of the current: that's why in my example I used just current direction to let the arrow point down.

For what concern the labels q and -q rather than insert them with the key info I preferred to used simple nodes: from one hand this allows to introduce C with info and from the other hand allows a better positioning of q and -q.

At last, to rotate the symbol of the voltage source I simply add to your code \pgftransformrotate{90} and I reduced a bit the size.

share|improve this answer
    
++ is used to add the following coordinate to the last used coordinate. In this example, it is equal to the sequence (0,0)--(1.5,0)--(4,0)--(4-3)--(0,-3)--(0,0). –  percusse Sep 2 '12 at 14:59
    
Yes: reading again what I wrote seem also to me a bit obscure :P; your comment clarifies what I had in mind. –  Claudio Fiandrino Sep 2 '12 at 15:07
    
No problem, that's meant for the general audience. –  percusse Sep 2 '12 at 15:35
add comment

@ClaudioFiandrino beat me to answer the question about ++ :), but I have some other improvements/remarks to make. See the modified code below:

\documentclass[10pt,a4paper]{standalone}
\usepackage{tikz}
\usetikzlibrary{circuits}
\usetikzlibrary{circuits.ee.IEC}
\tikzset{circuit declare symbol = ac source}
\tikzset{set ac source graphic = ac source IEC graphic}
\tikzset{
         ac source IEC graphic/.style=
          {
           transform shape,
           circuit symbol lines,
           circuit symbol size = width 3 height 3,
           shape=generic circle IEC,
           /pgf/generic circle IEC/before background=
            {
             \pgftransformresetnontranslations
             \pgfpathmoveto{\pgfpoint{-0.8\tikzcircuitssizeunit}{0\tikzcircuitssizeunit}}
             \pgfpathsine{\pgfpoint{0.4\tikzcircuitssizeunit}{0.4\tikzcircuitssizeunit}}
             \pgfpathcosine{\pgfpoint{0.4\tikzcircuitssizeunit}{-0.4\tikzcircuitssizeunit}}
             \pgfpathsine{\pgfpoint{0.4\tikzcircuitssizeunit}{-0.4\tikzcircuitssizeunit}}
             \pgfpathcosine{\pgfpoint{0.4\tikzcircuitssizeunit}{0.4\tikzcircuitssizeunit}}
             \pgfusepathqstroke
            }
          }
        }
\begin{document}

\begin{tikzpicture}[circuit ee IEC]
  \draw (0,0) to [capacitor={info={$q$\ \ $-q$}}]     ++(1, 0)
              to [resistor={info ={$R$}}]             ++(2, 0) 
              to [current direction = {info = {$I$}}]++(0,-2) 
              to [inductor={info=$L$}]                  (0,-2)  
              to [ac source={info={$V$}}]               (0,0);
\end{tikzpicture}

\end{document}

which has this as output:

enter image description here

First, it is a good idea to use \tikzcircuitssizeunit as unit, then the figure always scales correctly.

Second, \pgftransformresetnontranslations is also more general than having an explicit specification for a rotation of 90 degrees and makes the graphic reusable for any angle without extra effort.

Last, about the AC source, I'd like to point to this question (credit goes to @Jake for his great answer) posted by me (the very first I ever posted here on TeX.SE... ahhh - nostalgia... :)).

share|improve this answer
    
Oh: I wasn't aware of \pgftransformresetnontranslations! +1 for this :) –  Claudio Fiandrino Sep 2 '12 at 15:08
add comment

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.