# Drawing a circuit

How can I create the following drawing?

I want to add the following diagram to my report:

I hear it can be done in LaTeX so I read some of https://es.sharelatex.com/blog/2013/09/02/tikz-series-pt4.html and try this:

\documentclass{article}
\usepackage{circuitikz}
\usepackage{siunitx}
\begin{document}
\begin{center}
\begin{circuitikz}\draw
(0,0) to[battery] (0,6.5)
to[ammeter] (5.5,6.5) to[resistor] (5.5,0)

(2.5,0) to[voltmeter] (2.5,6.5)
;
\end{circuittikz}\end{center}
\end{document}


As you can see, I'm too bad, I market the coordinates in the corners.

• node[above left]{$(0; 6{,}5)$}? What is the question? What is the problem? Commented Jun 7, 2015 at 20:00
• @Qrrbrbirlbel I don;t think the OP wants to mark the corners, I think he's marked what the coordinates are supposed to be. Commented Jun 7, 2015 at 20:05
• Yes, I just marked the coordinates to help with diagram nodes. I don't know how to draw this large resistor or the box in batery Commented Jun 7, 2015 at 20:06
• Can you please post an example that actually compiles? You need to check the basic syntax of \draw... Each draw statement is supposed to end with a ; mark. Commented Jun 7, 2015 at 20:06
• @Thruston there is only one \draw statement, so there's only one ;; nothing wrong with that. The reason it doesn't compile is simply the typo in \end{circuittikz} (should be \end{circuitikz}). Commented Jun 7, 2015 at 22:14

A PSTricks solution using the pst-circ package:

\documentclass{article}

\usepackage{amsmath}  % used for the \overset macro
\usepackage{pst-circ} % used for the electrical components

\begin{document}

\begin{pspicture}(-1.25,0)(6.33,7) % boundry found manually
\psline[arrowscale = 1.5, arrowinset = 0]{->}(0,0)(3.5,0)(3.5,3.25)(5,3.25)
\psline(0,5)(0,6.5)(2.5,6.5)
\circledipole[labeloffset = 0](2.5,6.5)(5.5,6.5){A}
\psline(0,0)(0,1)
\vdc(0,3)(0,1){$\overset{+}{-}$}
\rput(-1,2){$\mathcal{E}$}
\resistor[dipolestyle = zigzag](0,3)(0,5){$r$}
\psframe[linestyle = dashed](-1.25,1.5)(1.0,4.9)
\circledipole[labeloffset = 0](2.5,0)(2.5,6.5){V}
\resistor[dipolestyle = zigzag](5.5,6.5)(5.5,0){$R$}
\psline(5.3,0)(5.7,0)
\end{pspicture}

\end{document}


• beautiful, but it doen't compile in my latex, no spaces between coordinates? Commented Jun 7, 2015 at 22:54
• @LuisFelipeVillavicencioLopez It compiles fine for me. You are using latex --> dvips --> ps2pdf, right? Also, what do you mean by "no spaces between coordinates"? Commented Jun 7, 2015 at 22:57
• I'm using Texstudio, I mean for example : ´\psline (5.3,0)--(5.7,0)´ Commented Jun 7, 2015 at 22:59
• That you are using TeXstudio has nothing to do with it; it's just your editor. Again: I don't understand what you mean; \psline(5.3,0)(5.7,0) is nothing more than a small line segment so what does "no spaces between coordinates" mean? Commented Jun 7, 2015 at 23:02
• ah, okey, It compiles fine in Overleaf.com, so I need to change to ps2pdf because i'm using latexpdf Commented Jun 7, 2015 at 23:03

Something like this (correcting the typo mentioned in the comments)?

\documentclass[tikz, border=5pt, multi]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{arrows.meta}
\usepackage{siunitx}
\begin{document}
\begin{circuitikz}
\draw (0,0)
to[battery] (0,6.5)
to[ammeter] (5.5,6.5) to[resistor] (5.5,0) (2.5,0) to[voltmeter] (2.5,6.5)
;
\end{circuitikz}
\end{document}


Extending it a bit and adding a few labels:

\begin{circuitikz}[font=\sffamily]
\draw
(0,0) to [battery, l=$\varepsilon$, n=batt] (0,3.25) to [R=r] (0,6.5) -- (2.5,6.5) to [ammeter] (5.5,6.5) to [R=R] (5.5,0) node [rground] {}
(0,0) -- (2.5,0) to [voltmeter] (2.5,6.5)
[-{Triangle[]}] (2.5,0) -- (3.5,0) |- (5,3.25)
;
\node [label=0:$+$] at ([xshift=12.5pt]batt.east) {};
\node [label=0:$-$] at ([xshift=12.5pt]batt.west) {};
\end{circuitikz}


# EDIT

I forgot to add the final version. You can use the fit library to create the dashed container around the battery and the resistor if you give them names.

\documentclass[tikz, border=5pt, multi]{standalone}
\usepackage{circuitikz}
\usetikzlibrary{arrows.meta,fit}
\usepackage{siunitx}
\begin{document}
\begin{circuitikz}[font=\sffamily]
\draw
(0,0) to [battery, l=$\varepsilon$, n=batt] (0,3.25) to [R=r,n=res] (0,6.5) -- (2.5,6.5) to [ammeter] (5.5,6.5) to [R=R] (5.5,0) node [rground] {}
(0,0) -- (2.5,0) to [voltmeter] (2.5,6.5)
[-{Triangle[]}] (2.5,0) -- (3.5,0) |- (5,3.25)
;
\node [label=0:$+$] at ([xshift=10pt]batt.east) {};
\node [label=0:$-$] at ([xshift=10pt]batt.west) {};
\node [dashed, draw, inner xsep=15pt, fit=(batt) (res)] {};
\end{circuitikz}
\end{document}


• The V-meter should be rotated for 90 degrees. Commented Jun 8, 2015 at 5:45
• @Zarko I'm sure you are right. I couldn't figure out how to do that, though. These don't seem to behave like regular nodes.... (This is the first time I've used circuitikz` and I did not find the documentation overly helpful. Doubtless my fault.)
– cfr
Commented Jun 8, 2015 at 12:50
• Somewhere in SE I sow the solution for this, but now I can't remember a question and answer for it. If I will find it or figured out how to do this, I will inform you about it. Commented Jun 8, 2015 at 14:27
• Here is solution for rotating V-meter: tex.stackexchange.com/questions/105864/… Commented Jun 8, 2015 at 14:28
• @Zarko Thanks. Having looked at the answers, I think I'll have to come back to this later. I had assumed I was missing something simple, but I guess not. On the other hand, I'm not sure that it should be rotated at all. Isn't non-rotation the intended behaviour? (By default, TikZ would not rotate the text, I don't think. So presumably the package does something specifically to ensure that it is rotated?) I haven't drawn one of these since high school, mind.
– cfr
Commented Jun 8, 2015 at 16:14