Circuits (circuitikz)

circuitikz was born in 2007 out of one lecturer’s very practical problem: making exercises and exams. Massimo Redaelli, then a research assistant at the Polytechnic University of Milan, needed a tool for setting the circuit diagrams that went into his course material, and what he wrote is the LaTeX package we still use. The syntax is disarmingly direct — write a wire as a path, drop to[R, l=$R_1$] into it, and a resistor appears. But the longest section on this page is not about syntax. It is about the fact that a resistor does not look the same in every country — zigzag or rectangle — and that circuitikz’s default is probably not the one you expect.

What \usepackage{circuitikz} actually loads

One line, \usepackage{circuitikz}, pulls in TikZ automatically, plus the TikZ libraries calc, arrows.meta, bending and fpu. So circuitikz is not an alternative to TikZ; it is TikZ with a vocabulary of electrical symbols bolted on. Paths and coordinates belong to the TikZ page; what matters here is the single fact that circuitikz commands are, in the end, all TikZ commands. It works as-is under pdfLaTeX, LuaLaTeX and XeLaTeX; only when you go through DVI — pLaTeX, upLaTeX — do you name a driver (usually dvipdfmx) as a class option, exactly as you would for TikZ.

document.tex
\documentclass{article}   % one schematic only: \documentclass[border=3pt]{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
  \draw (0,0) to[R, l=$R_1$] (2,0);
\end{circuitikz}
\end{document}

That “it is the same as TikZ” is not a metaphor here. Inside circuitikz.sty the circuitikz environment is defined in literally one line: \newenvironment{circuitikz}{\begin{tikzpicture}}{\end{tikzpicture}}. It is an empty alias. That is why \tikz \draw (0,0) to[R=$R_1$] (2,0); produces exactly the same picture from the tikzpicture side. And the fact bites in practice: TikZ’s \tikzexternalize (which caches each figure as its own PDF) assumes every picture ends with \end{tikzpicture}, so a document using the circuitikz environment stops with ! Emergency stop. The manual’s answer is blunt — replace every circuitikz with tikzpicture, since they are pretty much the same thing. If you only want one schematic exported as an image, the standalone class is the easy route.

Reading to[R, l=$R_1$]: dropping a part into a wire

One idiom explains nearly all of circuitikz. Put a component key in the brackets of TikZ’s path operation to, and one such component is inserted along the wire joining the two points. Read \draw (0,0) to[R, l=$R_1$] (2,0); as “go from (0,0) to (2,0), by way of resistor R₁.” Here l= is the label key — but to[R=$R_1$] does the same thing, being shorthand for to[R, l=$R_1$]. Seeing both forms side by side confuses a lot of people; they are identical. The long form leaves room to add i= or v= later, so once you are comfortable it pays to default to to[R, l=…].

latex
\begin{circuitikz}
  \draw (0,0) to[R, l=$R_1$] (2,0)   % long form
              to[C=$C_1$] (2,-2)     % shorthand for the same thing
              to[short, -*] (0,-2);  % bare wire, connection dot at the end
\end{circuitikz}

The result is a wire shaped like a bracket. Where you want a conductor but no component, use to[short] — a “two-terminal part that is nothing”, whose whole purpose is to let you keep writing the wiring as a chain of to. The trailing -* borrows TikZ’s arrow-tip notation to stamp a connection dot at the end of the path; use *-* for both ends. Coordinates are plain TikZ, so absolute (2,0) (default unit: centimetres) and relative ++(2,0) (2 cm to the right of where you are) both work. For right-angle routing there is (a -| b) — the point where a’s x-coordinate meets b’s y-coordinate — and the path operator -|. A component’s orientation follows the direction the path is heading, so a vertical run gives you a vertical symbol.

When you mistype a component key, the error does not look like a circuitikz error at all. Write to[resistorX] and you get ! Package pgfkeys Error: I do not know the key '/tikz/resistorX' and I am going to ignore it. Component keys really are TikZ keys, so it is pgfkeys that complains about an unknown one. The message quotes back the exact name you typed, which is the thread to pull on when checking your spelling.

Two-terminal component keys: R, C, L, D and the sources

What goes in to[…] is a part with two terminals — a bipole. Most keys are short mnemonic initials (R resistor, C capacitor, L inductor, D diode); the families with many members, such as sources, also carry spelled-out aliases like vsource and isource. The short forms are faster to type, the spelled-out ones kinder when you reread the code months later — on a shared document, leaning toward the spelled-out names saves arguments.

KeyComponentWritten as
RResistorto[R, l=$R_1$]
CCapacitorto[C, l=$C_1$]
LInductor (coil)to[L, l=$L_1$]
DDiode; leD (LED), zD (Zener) and others are siblingsto[D]
V / vsourceGeneric voltage sourceto[V, l=$U_q$]
I / isourceGeneric current sourceto[I, l=$I_0$]
sVSinusoidal voltage source (AC)to[sV, l=$v_s$]
battery1 / batteryBattery (single cell / multi-cell)to[battery1]
short / openPlain wire / open circuit (nothing in between)to[short]
closing switch / opening switchSwitch; the closing and opening senses draw differentlyto[closing switch]

Sources are worth a moment’s thought. V is the generic voltage source drawn as a circle, sV puts a sine wave inside it for AC, and battery1 is the battery’s own symbol of long and short strokes. Whether a DC supply should be a circle or a battery is a matter of local convention, so the safe move is to match the textbooks your readers already own. Switches split into closing switch and opening switch for the same reason: the symbol records which way that kind of switch moves, not whether it happens to be open right now.

american vs european: is a resistor a zigzag or a rectangle?

A resistor is a zigzag in the American convention and a hollow rectangle under IEC (the European one). Same component, same circuit, different picture. circuitikz surfaces the difference as a package option: \usepackage[american]{circuitikz} and \usepackage[european]{circuitikz} flip whole families at once — not just resistors, but inductors, logic gates, and the voltage and current arrows too. A schematic drawn in symbols your readers were not raised on is genuinely harder to read, so this is a decision to make before you start drawing, not after.

Now the real point: the default, if you specify nothing, is neither convention but a mixture. Read the default option list in circuitikz.sty and you find resistors and logic gates set American (americanresistors, americanports), voltage and current arrows set European (europeanvoltages, europeancurrents), and inductors on a third setting entirely, cuteinductors. The upshot is that an unconfigured schematic looks slightly foreign to American and European readers alike. And the difference is not subtle: a European voltage is a curved arrow arcing across the component, while an American voltage is a + and a placed at its terminals — two completely different pictures.

There are three places to set it, and one small trap. Package options carry no space (\usepackage[europeanresistors]{circuitikz}), while environment options and \ctikzset do (\begin{circuitikz}[european resistors]) — the names differ by exactly one character. For finer control there are keys: \ctikzset{resistor=european}, \ctikzset{voltage=american}. The clean division is to set [european] or [american] once in the preamble for the whole document, and use the environment option only where a single figure needs to break the rule.

document.tex
% whole document in IEC style (note: no space in package options)
\usepackage[european]{circuitikz}

% ... but this one figure keeps the American zigzag
\begin{circuitikz}[american resistors]
  \draw (0,0) to[R, l=$R_1$] (2,0);
\end{circuitikz}

Labels l=, voltages v=, currents i=, annotations a=

Four keys attach text to a component, and their jobs divide cleanly. l= is the name (R₁ and friends); a= is the annotation, a second line of information — often the actual value — placed on the opposite side from the name. v= draws the voltage across the part and i= the current through it, each with an arrow showing its direction. Every one of these takes a trailing underscore to flip sides or direction: l_= moves the label to the other side of the wire, i_= and v_= reverse the current and voltage arrows. A superscript form, l^=, exists too. Since “above” and “below” swap meaning depending on whether the wire runs horizontally or vertically, treat the choice between l and l_ as a last-minute visual decision rather than a rule to memorise.

latex
\begin{circuitikz}
  \draw (0,0) to[V, l=$U_q$] (0,2)
              to[short] (2,2)
              to[R, l=$R_1$, a=$4.7\,\mathrm{k}\Omega$, i=$i_1$, v=$u_1$] (2,0)
              to[short] (0,0);
\end{circuitikz}

What comes out is a closed loop: a voltage source Uq on the left, plain to[short] conductors along the top and bottom, and on the right a resistor carrying its name R₁ and its actual value 4.7 kΩ on opposite sides of the wire, plus arrows for the current i₁ and the voltage u₁. This is where the previous section pays off — how v=$u_1$ is drawn depends entirely on whether american voltages or european voltages is in force. With nothing specified the default is European, so you get the curved arrow arcing across the component.

To write values with units, load the package as \usepackage[siunitx]{circuitikz}. That enables circuitikz’s own number<\unit> notation — l=5<\ohm>, a=3<\micro\farad> — and hands the rest to siunitx, which sets “5 Ω” and “3 µF” properly. It takes the spacing between number and unit, and the shape of the µ, off your hands, so on any schematic that quotes real values it is worth switching on from the start.

Transistors, op-amps and ground go in \node[…]

A part with three or more terminals will not go in to[…]. to is an operation that fills the space between two points, so there is nowhere for a third leg to come out. Transistors, op-amps and ground are placed instead as TikZ nodes, in the form \node[part] (name) at (coordinate) {};. The braces {} are mandatory even when empty — forgetting them is a classic beginner’s stall. A placed node exposes an anchor at each terminal, which you reference as nodename.pin(oa.out) — to wire it up.

  • Ground\node[ground] at (0,0) {};. Power rails have their own symbols: vcc for the positive side, vee for the negative.
  • MOSFETs\node[nmos] (q1) {};, \node[pmos] {};. Bipolar transistors are npn/pnp. Their terminals answer to q1.gate, q1.drain, q1.source and so on.
  • Op-amp\node[op amp] (oa) {};, with pins oa.+ (non-inverting input), oa.- (inverting input) and oa.out (output).
  • Inline on a path — write node[ground]{} immediately after a coordinate to drop a node in without breaking the wire.
latex
\begin{circuitikz}
  \draw (0,0) node[op amp] (oa) {};
  \draw (oa.-) to[R, l=$R_f$] ++(0,2) -| (oa.out);  % feedback around the amp
  \draw (oa.+) to[short] ++(-1,0) node[ground] {};
\end{circuitikz}

This is where anchors earn their keep. Place one op-amp, run a feedback resistor R_f upward from the inverting input oa.-, turn right with -|, and drop onto the output oa.out — the feedback loop is closed. Notice that not a single coordinate was counted out by hand: if the op-amp symbol changes size, wiring written against anchors follows it. The non-inverting input oa.+ is pulled a little to the left and grounded.

\ctikzset: styling a whole schematic, and mixing with TikZ

\ctikzset{…} is how you decide the look of a whole schematic at once. It is circuitikz’s counterpart to TikZ’s \tikzset, usable in the preamble or in the middle of a figure. The single most useful setting in practice is \ctikzset{bipoles/length=1cm}, which gives every two-terminal part the same drawn length. Left at the defaults, components differ slightly in length and the spacing between them looks uneven; pinning the length is often all a messy figure needs. The resistor=american and voltage=european keys from the previous section belong to the same \ctikzset family.

Which brings us back to where we started: circuitikz sits on TikZ. calc for coordinate arithmetic, positioning for relative placement, a plain \node for a caption, colours, dash patterns, style definitions — anything TikZ can do still works. The more complex the circuit, the better the division of labour holds: build the layout the TikZ way and let circuitikz supply the parts. When the figures pile up and compilation drags, the external library caches them exactly as it does for TikZ — remembering, as above, to rewrite the circuitikz environment as tikzpicture first.