3

This is my first complete circuit in circuitiks. I'm trying to draw a circuit to show Kirchoff's Law. I was able to draw the nodes and voltages, but putting currents with arrow is giving me trouble.

  \documentclass{article}
  \usepackage{tikz}
  \usepackage[american,siunitx]{circuitikz}
  \usepackage{latexsym,amssymb,amsmath}
  \usepackage[active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
  \setlength\PreviewBorder{50pt}%

  \begin{document}


  \begin{tikzpicture} [auto, circuitikz]

  %produces error. Without i=$I$, it works
  \draw (0,0) to [R=$R_1$, v_=$v_1$, i=$I$, *-*] (2,0)
              -| (3,-1) 
              to [R=$R_2$, v_=$v_2$, *-*] (3,-3)
              |- (-1,-4) 
              to [battery, l = $V$, *-*] (-1,0)
              -- (0,0)
        (1,-2) node[scale=6]{$\circlearrowright$}
        (1,-2) node{$I$};

  \end{tikzpicture}

  \end{document}

The error that I'm getting is "! Package PGF Math Error: Unknown function `south' (in 'south')."

Secondly, I would like to move the voltage slightly away from the resistors. How can I do this?

0

2 Answers 2

6

This solution uses circuitikz environment rather than tikzpicutre environment, then the errors are gone. To move the v1 away from the resistor, raisebox{neg height}{content} is used while for the v2 only \,\, is used.

enter image description here

Code

  \documentclass{article}
  \usepackage{tikz}
  \usepackage[american,siunitx]{circuitikz}
  \usepackage{latexsym,amssymb,amsmath}
  \usepackage[active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
  \setlength\PreviewBorder{50pt}%

  \begin{document}


  \begin{circuitikz} 
  %produces error. Without i=$I$, it works
  \draw (0,0) to [R=$R_1$,v_=\raisebox{-10pt}{$v_1$}, i=$I$, *-*] (2,0)
              -| (3,-1) 
              to [R=$R_2$, v_={$v_2$\,\,}, *-*] (3,-3)
              |- (-1,-4) 
              to [battery, v_ = $V$, *-*] (-1,0)
              -- (0,0)
        (1,-2) node[scale=6]{$\circlearrowright$}
        (1,-2) node{$I$};
  \end{circuitikz}

  \end{document}
2
  • It is working also with tikzpicture environment; in particular, notice that the tikzpicture environment is absolutely mandatory while performing externalizations, see Compiling CircuiTikZ with -shell-escape (pdflatex). Feb 20, 2014 at 12:51
  • @ClaudioFiandrino -- Yes, you are right. But I did confirm the problem while trying to solve the OP's problem when investigating what went wrong. Then, my instinct was to try circuitikz instead and then the errors went disappeared. Just now, after reading your comment and link, I recheck my code and it does work. Thanks for your feedback.
    – Jesse
    Feb 20, 2014 at 13:04
2

As far as I can see, the cause of the original error message was the auto option, which seems to be incompatible with the way currents are typeset in circuitikz. I ran into the same problem and had to debug for quite some time before I found out that the culprit was a \tikzset{auto} that I had in the file header, that I needed for a number of other tikz figures in the same document. Since I wanted to keep this default setting in the document, I ended up doing \begin{circuitikz}[auto=false] for the few circuitikz illustrations I had.

You must log in to answer this question.

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