# Wiring diagrams using LaTeX and TikZ

Sometimes in LaTeX you need to draw a simple electrical circuit. The following describes how to do this without involving third-party software using LaTeX itself. What will be written below is designed for those who are already familiar with such a vector creation tool for LaTeX as TikZ. Otherwise, you must first familiarize yourself with TikZ. Some information in Russian is here . Those who are already familiar with TikZ - see under cat. These methods of drawing schemes in LaTeX I used in the process of writing a dissertation.

Here is a diagram you can draw using LaTeX:

### TikZ with circuits library

For drawing electrical circuits, a library of circuits is used. It must be connected in the preamble of the document using the \ usetikzlibrary command. Additionally, you must specify
circuit ee IEC as the environment parameter tikzpicture .

\usetikzlibrary{circuits}
\usetikzlibrary{circuits.ee}
\usetikzlibrary{circuits.ee.IEC}
\usetikzlibrary{circuits.logic.IEC}


Schema elements in this library are special types of nodes and are defined as regular TikZ nodes with the \ node command. Here you need to pay attention that the node text specified in curly brackets for radio elements is always empty. The reference designation and face value are entered as parameter info in square brackets. The point up parameter rotates the component 90 degrees, and the point down parameter 270 degrees.

\node (R) [resistor={info={$R$}}] at (2,2) {}; % горизонтальный резистор
\node (C1) at (3,0) [point up,capacitor={info = $C_1$, info'= 100 пФ}] {}; %вертикальный конденсатор


A complete list of all components is available in the TikZ documentation.
The circuit node is defined by a special contact node, which draws a filled circle.

\node (p2) [contact] at (6,-2) {}; % узел в точке x=6, y=-2


The wires between the elements are set as usual in TikZ with the / draw command. A straight wire is drawn by the command

\draw (R1) -- (C1);


And the wire at an angle of 90 degrees is drawn with the command:

\draw (R1) |- (C1);


or
\draw (R1) -| (C1);


The difference is that in the first case, the wire goes first vertically, and then horizontally, and in the second case - vice versa.

All parameters can be applied to wires (arrows, line thickness, as well as to ordinary trajectories. For example, a thick wire with an arrow:
\draw [thick,->] (R1) -| (C1);


Schemes can be combined with any TikZ graphics and, for example, place a chart on the scheme.

Now consider a small example that has comments.

\documentclass[12pt]{article}
\usepackage{mathtext}
\usepackage[T2A]{fontenc}
\usepackage[koi8-r]{inputenc}
\usepackage[russian]{babel}
\usepackage[pdftex]{graphics}
\usepackage{tikz}
\usetikzlibrary{circuits} % подключаем библиотеки, содержащие
\usetikzlibrary{circuits.ee} % УГО для схем
\usetikzlibrary{circuits.ee.IEC}
\usetikzlibrary{arrows} % подключаем библиотеки со стрелками
\usetikzlibrary{patterns} % и со штриховкой
\begin{document}
Мега-описание RLC-контура
\begin{figure}[!h]
\begin{center}
\begin{tikzpicture}[circuit ee IEC] % обязательно указываем circuit ee IEC
\node (in) at (0,0) [contact] {}; % вход - контакт
\node (L1) at (1,0) [inductor={info = $L_1$, info'= 47 мкГн}] {}; % катушка -
% info - обозначение на схеме , info' - номинал
\node (C1) at (3,0) [capacitor={info = $C_1$, info'= 100 пФ}] {}; % конденсатор
\node (R) at (5,0) [resistor={info = $R_1$, info'= 2 Ом}] {}; % резистор
\node (out) at (6,0) [contact] {}; % выходной зажим
\draw (in) -- (L1) -- (C1) -- (R) -- (out); %выходной зажим
\end{tikzpicture}
\end{center}
\caption{Последовательный колебательный контур}
\end{figure}
\begin{figure}[!h]
\begin{center}
\begin{tikzpicture}[circuit ee IEC]
\node (R) [resistor={info={$R$}}] at (2,2) {}; % рисуем резистор
\node (p1) [contact] at (3,2) {}; % рисуем точку соединения R и С
\node (C) [point up, capacitor={info={$C$}}] at (3,1) {}; % конденстаор развернём на 90 градусов
\node (p2) [contact] at (3,0) {}; % рисуем точку соединения конденсатора с общи проводом
\draw [-latex] (p1) -- (5,2); % соединяем узлы схемы, R и С
\draw [latex-] (0,2) -- (R);
\draw (R) -- (p1) -- (C) -- (p2); % рисуем провода
\draw [latex-] (0,0) -- (p2);
\draw [-latex] (p2) -- (5,0);
\node  at (0,1) {Вход}; % подписываем где Вход
\node  at (5,1) {Выход}; % и где Выход
% теперь рисуем АЧХ как обычно график
\draw[xshift=60mm,-latex] (0,0) -- (4,0) node [anchor=west] {$\omega$}; % ось Х
\draw[xshift=60mm,-latex] (0,0) -- (0,3) node [anchor=south] {$K(\omega)$}; % ось Y
\draw [very thick,xshift=60mm, y=2cm, x=1cm,
declare function={K(\w)=1/sqrt(1+\w^2);}] plot [domain=0:3, samples=10,
smooth] (\x,{K(\x)}); % график АЧХ
\end{tikzpicture}
\end{center}
\caption{RC - цепочка и её АЧХ}
\end{figure}
\end{document}


The result looks like this:

### Circuitikz package

The circuitikz package is a further development of the cirtuits library. The package contains significantly more components: passive components, transistors, diodes, thyristors, logic gates, transformers. The circuitikz package is not compatible with the circuits library. You can not use them together. The documentation for the package can be downloaded here.

The circuitikz package is connected in the preamble like this:

\usepackage[europeanresistors,americaninductors]{circuitikz}


With such parameters, UGOs are obtained closest to our GOSTs.

The package defines a special environment in which to place the circuit:
\begin{circuitikz}
\end{circuitikz}


It is not necessary to place this environment inside the tikzpicture.

The ideology of drawing schemes is different from the circuits library. Components are not nodes, but paths. To place a single component, you need to create the path with the / draw command. The rotation of the component is carried out by the orientation of the path. As an example, consider the circuit of a thyristor phase regulator.

\begin{circuitikz}
\draw (-1,0) to [sV,l=$U_c$] (-1,2) % источник синусоидального напряжения
to [R, l=$R_н$,i>_=$I_н$] (2,2) % резистор  с направлением тока
to [Ty,l={VS},*-,n=VS] (2,0); % тиристор
\draw (VS.G) to [R,mirror,l=$R_у$,i<_=$I_у$] ++(4,0) |- (2,2);
\draw (VS.cathode) |- (-1,0);
\end{circuitikz}


The result is the following:

### conclusions

To draw circuits in LaTeX, you can use the circuits library for TikZ or the circuitikz package. I would recommend the latter package only for drawing complex circuits with semiconductor components. I usually prefer to use the circuits library. Schemes made using each of these methods do not look foreign in LaTeX; the same font and line style is used as in the rest of the document. Also, all illustrations are embedded in the document and everything is stored in a single file.

The disadvantage is that large schemes slow down the compilation of the document, since each time they are compiled, they are rendered again. Also, drawing time with TikZ tools takes more time than using visual editors.

Resources:
1. More examples of circuits made using TikZ and circuitikz: www.texample.net/tikz/examples/area/electrical-engineering
2. Circuittikz documentation: texdoc.net/show.php?pkg=circuitikz
3. List of free software for drawing electrical circuits: https://en.wikipedia.org/wiki/Wikipedia:WikiProject_Electronics/Programs