Pictures go into LaTeX documents through the graphicx package, which lets you place image files anywhere in your text

LaTeX does not have a built-in drawing tool like Microsoft Word does. Instead, you insert image files (JPG, PNG, PDF) that you created elsewhere, or you write code that tells LaTeX to draw shapes and lines for you. Most people use the first method — inserting photos or diagrams they already have. The second method, drawing with code, is useful when you need precise geometric shapes or when you want the image to match your document's fonts and styling.

This guide covers both approaches: how to insert existing images into your document, and how to draw basic shapes and diagrams using LaTeX code.

Key Takeaways

  • To insert an image file, add \usepackage{graphicx} to your preamble, then use the \includegraphics command with the filename and width or height.
  • Image files must be in the same folder as your LaTeX document, or you must provide the full path to the file.
  • The tikz package lets you draw shapes, lines, and diagrams using code instead of inserting image files.
  • Wrapping images in a figure environment lets you add captions, labels, and position the image precisely on the page.
  • Common mistakes include forgetting the file extension, placing images outside the document folder, and not scaling images to fit the page width.

Inserting an existing image file with graphicx

The graphicx package is the standard way to add photographs, screenshots, or diagrams you have already created. First, add this line to your preamble (the section before \begin{document}):

\usepackage{graphicx}

Then, in the body of your document where you want the image to appear, use the \includegraphics command. The simplest version looks like this:

\includegraphics{myimage.png}

This inserts the image at its original size. Usually you want to scale it. Add a width or height parameter:

\includegraphics[width=0.8\textwidth]{myimage.png}

This makes the image 80 percent as wide as your text area. You can also use height=5cm or scale=0.5 instead. If you specify only width or height, LaTeX keeps the image's original proportions.

The image file must be in the same folder as your LaTeX document, or you must give the full path. On Windows, use forward slashes even though Windows uses backslashes: \includegraphics{images/myimage.png} not images\myimage.png.

Placing images in a figure environment for captions and positioning

A bare \includegraphics command places the image exactly where you type it, which often breaks your page layout. Wrapping it in a figure environment lets LaTeX move the image to the top or bottom of a page and add a caption:

\begin{figure}[h]\centering\includegraphics[width=0.7\textwidth]{myimage.png}\caption{This is the image caption}\label{fig:myimage}\end{figure}

The [h] tells LaTeX to place the figure "here" if possible. Other options are [t] for top of page, [b] for bottom, and [p] for a page of floats. The \centering command centers the image. The \caption adds text below the image, and \label lets you reference the figure elsewhere in your document with \ref{fig:myimage}.

If you want the image to stay exactly where you type it and not float to another page, use the H option instead: \begin{figure}[H]. This requires adding \usepackage{float} to your preamble.

Drawing shapes and diagrams with the tikz package

When you need to draw lines, circles, rectangles, or more complex diagrams, the tikz package lets you specify them with code. Add this to your preamble:

\usepackage{tikz}

Then create a drawing environment in your document:

\begin{tikzpicture}\draw (0,0) -- (3,0) -- (3,2) -- (0,2) -- cycle;\end{tikzpicture}

This draws a rectangle. The coordinates are in centimeters by default. (0,0) is the bottom-left corner, (3,0) is three centimeters to the right, and cycle closes the shape by returning to the starting point.

Here are common tikz commands:

  • \draw (0,0) -- (2,2); draws a line from one point to another
  • \draw (1,1) circle (0.5); draws a circle with center at (1,1) and radius 0.5 cm
  • \draw (0,0) rectangle (2,1); draws a rectangle from (0,0) to (2,1)
  • \node at (1,1) {text}; places text at a specific location
  • \draw[thick, red] ... makes the line thicker and red

Tikz diagrams scale with your document and use the same fonts as your text, which makes them look polished. For complex diagrams, the learning curve is steeper, but for simple flowcharts, graphs, or geometric shapes, tikz is faster than creating an image file.

Sizing and positioning images on the page

Images that are too large break your page layout. Always specify a width or height when using \includegraphics. Common approaches:

  • width=\textwidth makes the image as wide as your text area (usually too large; use 0.8\textwidth or 0.6\textwidth instead)
  • width=10cm sets a fixed width in centimeters
  • scale=0.5 shrinks the image to half its original size

If your image is wider than the page, LaTeX will shrink it automatically, but the result often looks wrong. Test your document by compiling it and checking the PDF. If an image overflows the margin, reduce the width value.

To place an image beside text instead of above or below it, use the wrapfig package. Add \usepackage{wrapfig} to your preamble, then wrap your image:

\begin{wrapfigure}{r}{0.4\textwidth}\includegraphics[width=0.38\textwidth]{myimage.png}\end{wrapfigure}

The {r} places the image on the right; use {l} for left. The text flows around it. This works best with narrow images and short blocks of text.

Troubleshooting common image problems

If your image does not appear, check these things first. The most common error is a missing file extension. LaTeX needs the full filename including .png, .jpg, or .pdf. If you type \includegraphics{myimage} without the extension, LaTeX will not find it.

Second, make sure the file is in the right location. If your LaTeX document is in a folder called project and your image is in a subfolder called images, use \includegraphics{images/myimage.png}. If the image is in a different folder entirely, provide the full path from your document's location.

Third, check that you added \usepackage{graphicx} to your preamble. Without it, the \includegraphics command will not work. If you are using tikz, make sure \usepackage{tikz} is there too.

If the image appears but looks blurry or pixelated, it may be scaled too large. Reduce the width value. If it is a photograph, make sure the original file is high resolution (at least 150 DPI for print, 72 DPI for screen). If it is a diagram or screenshot, PNG usually looks better than JPG.

Frequently Asked Questions

Can I use images from the internet directly in my LaTeX document?

No. You must download the image file to your computer first, save it in the same folder as your LaTeX document (or a subfolder), and then reference it with \includegraphics. LaTeX does not fetch files from URLs.

What image formats does LaTeX support?

The graphicx package supports PNG, JPG, and PDF. PNG is best for diagrams and screenshots. JPG is best for photographs. PDF works well for vector graphics created in other programs. Avoid BMP and GIF.

How do I rotate an image in LaTeX?

Add the angle parameter to \includegraphics: \includegraphics[width=5cm, angle=90]{myimage.png}. The angle is in degrees, and positive numbers rotate counterclockwise.

Can I draw text inside a tikz diagram?

Yes, use the \node command: \node at (1,1) {My Text};. You can also style the text with options like \node[font=\large, red] at (1,1) {My Text};.

What should I do if my image is too large for the page?

Reduce the width value in \includegraphics. Start with width=0.8\textwidth and adjust down if needed. Compile your document and check the PDF to see if it fits. If the image is a photograph, you can also compress it with an image editor before inserting it.