Circuits (circuitikz)

circuitikz is a package for drawing electrical and electronic schematics directly inside LaTeX, in code. Built on top of TikZ/PGF, it knows your parts — resistors, capacitors, sources, transistors — as proper symbols. You write the wiring as a path and drop components into it with idioms like to[R=…], and a schematic of the same quality as the surrounding text falls out.

What it is — getting started

TikZ is a general drawing system that deals in raw shapes — lines, circles, nodes (covered separately on “TikZ basics”). circuitikz takes that TikZ foundation and adds a vocabulary of electrical symbols. You never hand-draw the zigzag of a resistor: you name the component key R, and a properly oriented symbol — with terminals and the right line weight — is placed for you. It was created by Massimo A. Redaelli and contributors.

To begin, load \usepackage{circuitikz} in your preamble (TikZ is pulled in with it). It works as-is with pdfLaTeX, LuaLaTeX, and XeLaTeX. When you go through DVI — as with pLaTeX or upLaTeX — specify a driver (usually dvipdfmx) as a class option, exactly as with TikZ. If you want a single standalone schematic to export as an image, the standalone class is handy.

document.tex
\documentclass{article}   % 回路図1枚なら \documentclass[border=3pt]{standalone}
\usepackage{circuitikz}
\begin{document}
\begin{circuitikz}
  \draw (0,0) to[R=$R_1$] (2,0);
\end{circuitikz}
\end{document}

This runs a wire from the origin (0,0) rightward to (2,0), places one resistor symbol along the way, and sets the label “R₁” above it. The basic form is to write your drawing commands inside the dedicated **circuitikz environment**. Its contents follow ordinary TikZ syntax — you could instead use \begin{tikzpicture} with circuitikz’s libraries loaded — but learning this environment first is all you need.

The core idiom — to[…] places a component

Everything in circuitikz is captured by one line. Inside the brackets of TikZ’s path operation **to, you name a component key, and one such component is inserted along** the wire joining the two points. For example \draw (0,0) to[R=$R_1$] (2,0); reads “go from (0,0) to (2,0), passing through resistor R₁.” Chain these and you get a circuit of wires and parts in alternation.

latex
\begin{circuitikz}
  \draw (0,0) to[R=$R_1$] (2,0)
              to[C=$C_1$] (2,-2);
\end{circuitikz}

This draws an L-shaped wire: a resistor R₁ along the path going right from (0,0), then a capacitor C₁ along the path going down from (2,0). The shorthand at work is that **writing =label right after a component key makes it that component’s label** — so to[R=$R_1$] is the short form of to[R, l=$R_1$] (below). When you only want a bare wire with no component, use **to[short]** (a plain conductor).

Coordinates are plain TikZ: Cartesian (x,y) (default unit centimeters), and the handy (a -| b) (the point where a’s x-coordinate meets b’s y-coordinate) for routing right-angle wires. A component’s orientation automatically follows the direction the path is heading.

Common two-terminal parts (bipoles)

What you place in to[…] are bipoles — parts with two terminals. The table below lists the frequent ones. Component keys are mostly mnemonic initials (R resistor, C capacitor, L inductor), with sources and diodes also having spelled-out aliases.

KeyComponentExample
RResistorto[R=$R_1$]
CCapacitorto[C=$C_1$]
LInductor (coil)to[L=$L_1$]
battery / battery1Battery (multi-/single-cell)to[battery1]
V / vsourceVoltage sourceto[V=$U_q$]
I / isourceCurrent sourceto[I=$I_0$]
DDiodeto[D]
short / openWire / open circuitto[short]
closing switchSwitch (open/closing)to[closing switch]

Sources differ by symbol and purpose: V (vsource) is a generic voltage source (a circle, often with a sine wave), battery1 is the battery symbol, and sV is a sinusoidal source for AC. Switches distinguish their state: closing switch (an open switch shown closing) and opening switch. Beyond the default diode D, light-emitting, Zener, and other diode types are selectable by key.

Labels and voltage/current annotations

A label puts a value or name beside a part. The basic key is l=…, which gives the same result as the to[R=$R_1$] shorthand. You choose which side of the component the label sits on with a marker: l_=… pushes it to the other side (below or inside the line), l^=… to the opposite side (above or outside). Since “above/below” depends on whether the wire runs vertically or horizontally, you switch between l and l_ to taste.

Schematics often need to show not just a part’s value but the current through it or the voltage across it, with an arrow. Dedicated keys handle this: **i=… draws a current (an arrow along the component) and v=…** draws a voltage (an arrow spanning the component). To flip the direction, add an underscore: i_=… or v_=….

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

This is a closed loop: a voltage source Uq on the left vertical side, a plain wire across the top, resistor R₁ on the right vertical side, and to[short] wires closing the rest. The resistor carries two arrows — one for the current i₁ through it, one for the voltage u₁ across it. The to[short] segments are what turn the remaining sides into bare conductors that close the loop.

To write values with units in a label, load the package with the [siunitx] option (\usepackage[siunitx]{circuitikz}); then the number<\unit> form works, as in l=5<\ohm> or l=3<\micro\farad>, typeset correctly as “5 Ω” and “3 µF.”

Node-style parts and styling

Parts with three or more terminals — transistors, op-amps, ground — cannot go in to[…]. You place these as TikZ nodes: \node[part] (name) at (coordinate) {};. The braces {} are mandatory even when empty. Each placed node exposes anchors at its terminals, which you reference by name — like (name.output-pin) — to wire it up.

  • Ground\node[ground] at (0,0) {};. Use vcc/vee for power-rail symbols.
  • MOSFETs\node[nmos] (q1) {};, \node[pmos] {};. Bipolar transistors are npn/pnp.
  • Op-amp\node[op amp] (oa) {};. Reference its pins as oa.+ (non-inverting input), oa.- (inverting input), oa.out (output).
  • To place a node along a path, write node[nmos]{} after a coordinate (e.g. (0,0) node[nmos]{} (2,0)).

Symbol conventions vary by country and field. You choose whether a resistor is drawn as a rectangle (IEC / European) or a zigzag (American): pass [american]/[european] as an environment option (or the finer [american resistors]/[european resistors]), or set a key like resistor=american. Inductors likewise come in cute/american/european variants.

To style a whole schematic at once, use **\ctikzset{…}** — circuitikz’s counterpart to TikZ’s \tikzset, usable in the preamble or mid-code. With it you can, say, make lines heavier or fix the voltage-arrow convention to American (american voltages).

document.tex
\usepackage[siunitx, american]{circuitikz}
\ctikzset{bipoles/length=1cm}      % 部品の長さをそろえる

\begin{circuitikz}
  \draw (0,0) node[ground]{} to[V=$U_q$] (0,2)
              to[R=$R_1$] (2,2)
              to[C=$C_1$] (2,0) -- (0,0);
\end{circuitikz}

This is a closed loop grounded at the lower left, with a voltage source Uq on the left, an American (zigzag) resistor R₁ across the top, and a capacitor C₁ on the right. The final -- (0,0) is a plain TikZ straight line closing the bottom as a wire (the same role as to[short]). Because \ctikzset fixes component length to 1 cm, the symbols are evenly spaced.

Because circuitikz sits on TikZ, you can freely combine TikZ’s own facilities — calc for coordinate arithmetic, positioning for relative placement, plain \node for labels, colors and styles. For complex circuits the natural division of labor is to lay out the structure the TikZ way and let circuitikz supply the parts. If compilation gets heavy, the external library caches each figure, just as in TikZ.