How to Add circuit diagrams in LaTeX

How to Add circuit diagrams in LaTeX

This post may contain affiliate links that allow us to earn a commission at no expense to you. Learn more

LaTeX is a document creation and processing system that can handle all sorts of complex tasks. One of these is creating and adding circuit diagrams to documents. 

Creating circuit diagrams can seem complicated at first. However, it is possible to create some very complex circuit diagrams once you understand the correct commands and syntax involved. Let’s examine how to add circuit diagrams in LaTeX.

What is a Circuit Diagram?

Before looking at the different ways to add circuit diagrams to LaTeX, it is worth learning what exactly they are and what they contain.

A circuit diagram is simply a graphical representation of a circuit. They typically show the various components in the circuit and represent them using different symbols. These components typically include:

  • A voltage source
  • A conductive path
  • A resistor

Many circuit diagrams also feature capacitors and other components. Circuit diagrams are used by many types of professionals. They are especially useful in circuit design, construction, and maintenance tasks.

Why You Need Circuitikz Package for Circuit Diagrams

LaTeX is able to create and insert various types of content into documents using different packages. If you wish to create and add circuit diagrams, you will need to use the circuitikz package. This is based on the special package TikZ

You can load up the package using the command \usepackage{circuitikz}. This automatically loads the TikZ package and allows you to draw your circuit diagrams.

Loading circuitikz using the above command creates the circuitikz environment. You can then fill this environment using various codes and commands.

Creating Simple Circuit Diagrams in LaTeX

We show how to create a simple circuit diagram using the following code:

\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{figure}[h!]
  \begin{center}
    \begin{circuitikz}
      \draw (0,0)
      to[V,v=$U_q$] (0,2)
      to[short] (2,2)
      to[R=$R_1$] (2,0)
      to[short] (0,0);
    \end{circuitikz}
    \caption{Example of a circuit.}
  \end{center}
\end{figure}
\end{document}

In the above example, we started the circuit at coordinates (0,0) using the code       \draw (0,0). We then used the code to[V,v=$U_q$] (0,2) to draw the voltage from the voltage source towards the coordinates (0,2). The V in the aforementioned code signifies that there is a voltage source while the code v=$U_q$ illustrates the voltage by drawing a labelled arrow next to it.

Next, the voltage is drawn to the resistor. This is accomplished using the following code:

to[short] (2,2)

to[R=$R_1$] (2,0)

In the above code, we first drew the circuit from coordinates (0,2) to (2,2) and added a resistor in the path leading from coordinates (2,2) to (2,0). We specified the resistor label using the code (R=$R_1$).

Adding Inductors to Your Circuits

It is also possible to add an inductor to the above circuit. We do this using the following code:

\begin{circuitikz}
      \draw (0,0)
      to[V,v=$U_q$] (0,2) 
      to[short] (2,2)
      to[R=$R_1$] (2,0) 
      to[short] (0,0);
      \draw (2,2)
      to[short] (4,2)
      to[L=$L_1$] (4,0)
      to[short] (2,0);
   \end{circuitikz}

In the above code the command to[L=$L_1$] (4,0) describes the inductor.

Adding a Capacitor to Your Circuits

You can add capacitors to your circuits with relative ease. We show this using the following code:

\begin{circuitikz}
      \draw (0,0)
      to[V,v=$U_q$] (0,2) 
      to[short] (2,2)
      to[R=$R_1$] (2,0) 
      to[short] (0,0);
      \draw (2,2)
      to[short] (4,2)
      to[L=$L_1$] (4,0)
      to[short] (2,0);
   \end{circuitikz}

You can see the capacitor represented in the above code with to[C=$C_1$] (6,0).

Changing the Appearance of Circuit Lines

It is also possible to change the appearance of the circuit lines in your diagram. For example, we can draw a short circuit line using the following code:

\begin{figure}[h!]
\begin{circuitikz}
  \draw (-1,0) to[short,o-o] (1,0);
\end{circuitikz}
\end{figure}

In the above code, we drew an upper line section that features an open connector with either end. We can alter the connectors by making changes to the 0-0 in the above code. For example, if we change this portion to *- instead, it creates a different type of connector.

Final Thoughts

As you can see, LaTeX offers many options for creating circuit diagrams. Most people won’t need to use such diagrams in their documents. 

However, if you are an electrician, electrical engineer, or a circuit designer, the above guide should be incredibly useful for you. So try experimenting with circuit diagrams in LaTeX when working on your next document.

You can learn more about creating circuit diagrams using circuitikz by watching this video.

Frequently Asked Questions

Some frequently asked questions related to circuit diagrams in LaTeX are shown below.

Q1. How Do You Draw Circuits in Overleaf?

You can draw circuits in Overleaf using the following code format:
\documentclass{article}
\usepackage{tikz}
\usepackage{circuitikz}
\begin{document}
\begin{figure}[h!]
\begin{center}
\begin{circuitikz}
[CIRCUIT COMPONENTS]
\end{circuitikz}
\caption{YOUR CIRCUIT NAME}
\end{center}
\end{figure}
\end{document}

Q2. How Do You Draw Resistance in LaTeX?

You can add a resistor to your circuit using the command to[R=$R_1$]

Q3. How Do I Make a Circuit Diagram Online?

You can create circuit diagrams online using different tools such as Circuit Diagram. However, it is generally best to create your circuit diagrams in LaTeX itself.

Further Reading

LaTex Tutorial

  1. 27 Pros and Cons of Using LaTex for Scientific Writing
  2. 6 Easy steps to create your first Latex document examples
  3. How to change Latex font and font size
  4. How to create a Latex table of contents
  5. How to create footnotes in LaTeX and how to refer to them, using the builtin commands
  6. How to create Glossaries in LaTeX
  7. How to create plots in Latex – codes and examples
  8. How to create symbols in LaTeX – commands for Latex greek alphabet
  9. How to create tables in LaTeX – rows, columns, pages and landscape tables
  10. How to drawing graphs in Latex – vector graphics with tikz
  11. How to highlight source code in LaTeX
  12. How to insert an image in LaTeX – Managing Latex figure and picture
  13. How to Itemize and Number List – Adding Latex Bullet Points
  14. How to make hyperlink in latex – Clickable links
  15. How to reference in Latex – 5 steps to bibliography with Bibtex
  16. How to use Latex Packages with examples
  17. How to use LaTeX paragraphs and sections
  18. LaTeX Installation Guide – Easy to follow steps to install LaTex
  19. Learn to typeset and align Latex equations and math

Photo of author
Author
Joannah W.
Joannah has been a science publisher with close to 20 years of experience. She wants to help students and researchers stay ahead of the trends and developments in the science community by making science more accessible to everyone.

Leave a Comment