Pictures in LaTeX work differently than in Word — you either embed image files or draw shapes with code

LaTeX handles images in two separate ways. You can insert a photograph, screenshot, or graphic file (like a PNG or JPG) using the graphicx package, which is the most common approach. Or you can draw shapes, lines, and diagrams directly in LaTeX code using packages like TikZ or PGF. Most people use the first method for photos and the second for technical diagrams. Both require you to write a few lines of code rather than drag-and-drop, but once you understand the pattern, it becomes routine.

The privacy advantage of LaTeX here is that you control exactly what gets embedded in your document. You are not relying on a cloud service to process your images, and you can see the code that places them. If you are working with sensitive photographs or diagrams, this transparency matters.

Key Takeaways

  • To insert an image file, load the graphicx package at the top of your document, then use the \includegraphics command with the filename and width or height.
  • Image files must be in the same folder as your LaTeX file, or you must provide the correct path to where they are stored.
  • You can draw shapes and diagrams directly in LaTeX code using the TikZ package, which gives you precise control but requires learning the syntax.
  • LaTeX does not automatically resize images to fit your page — you set the size yourself, so oversized images will run off the edge unless you specify a width.

Inserting an image file with graphicx

Start by adding one line near the top of your LaTeX document, after \documentclass but before \begin{document}:

\usepackage{graphicx}

This loads the package that lets you insert images. Then, wherever you want the image to appear in your document, write:

\includegraphics[width=4in]{myimage.png}

Replace myimage.png with the actual filename. The width=4in part tells LaTeX how wide to make the image — you can use inches (in), centimeters (cm), or a fraction of the page width like width=0.8\textwidth. If you specify only the width, LaTeX automatically scales the height to keep the image from looking stretched. You can also use height instead of width, or both together if you want exact dimensions.

The image file must be in the same folder as your LaTeX document, or you need to tell LaTeX where to find it. If your image is in a subfolder called images, write \includegraphics[width=4in]{images/myimage.png}.

Centering images and adding captions

By default, an image sits at the left margin. To center it, wrap the command in a center environment:

\begin{center} \includegraphics[width=4in]{myimage.png} \end{center}

To add a caption and a label (so you can refer to the image later in your text), use a figure environment instead:

\begin{figure}[h] \centering \includegraphics[width=4in]{myimage.png} \caption{This is my image caption} \label{fig:myimage} \end{figure}

The [h] tells LaTeX to place the figure "here" on the page (other options are t for top, b for bottom, or p for a dedicated page). The \label lets you write \ref{fig:myimage} elsewhere in your document to automatically insert the figure number — so if you add a new figure earlier, all the numbers update without you having to edit them by hand.

Drawing shapes and diagrams with TikZ

If you want to create a diagram, flowchart, or geometric shape directly in LaTeX, use the TikZ package. Add this near the top of your document:

\usepackage{tikz}

Then create a straightforward shape like a circle:

\begin{tikzpicture} \draw (0,0) circle (1cm); \end{tikzpicture}

This draws a circle centered at coordinates (0,0) with a radius of 1 centimeter. You can draw rectangles, lines, text, and much more. A rectangle looks like:

\draw (0,0) rectangle (2,1);

This creates a rectangle from point (0,0) to point (2,1). You can add color, fill, line thickness, and labels. The learning curve is steeper than inserting an image file, but TikZ diagrams scale perfectly and look professional. Many people use TikZ for flowcharts, network diagrams, and mathematical plots.

Common problems and how to fix them

If your image does not appear, the most common cause is that LaTeX cannot find the file. Check that the filename in your code matches exactly — including capitalization and the file extension. If the file is in a different folder, make sure the path is correct. Some LaTeX editors let you see error messages that point to the problem; look for a message like "File not found" or "Cannot open image".

If your image is too large and runs off the page, you specified a width that is too big. Try width=0.9\textwidth to make it 90 percent of the page width, or measure your image and set a specific size like width=3in. If the image looks blurry or pixelated, the original file may be low resolution — there is no way to fix that in LaTeX, but you can make it smaller so the pixels are less obvious.

If you are using TikZ and your diagram does not compile, check that every command ends with a semicolon. TikZ is strict about syntax. Start with straightforward shapes and add complexity once you see the pattern working.

File formats and what works best

LaTeX works with PNG, JPG, PDF, and EPS files. PNG and JPG are the most common for photographs and screenshots. PDF is useful if you have a diagram created in another program — you can export it as PDF and insert it into LaTeX without losing quality. EPS (Encapsulated PostScript) is older but still supported.

If you are inserting a PDF file, the syntax is the same: \includegraphics[width=4in]{mydiagram.pdf}. This is especially useful if you create a diagram in a drawing program, export it as PDF, and then include it in your LaTeX document. The PDF stays as a vector graphic, so it scales without becoming blurry.

For TikZ diagrams, you do not need a separate file — the code lives in your LaTeX document itself. This means your entire document is self-contained and portable. You can email it to someone else, and they see the exact same diagram without needing to manage separate image files.

Frequently Asked Questions

Can I rotate or flip an image in LaTeX?

Yes. Add angle=90 to rotate the image 90 degrees clockwise: \includegraphics[width=4in,angle=90]{myimage.png}. You can use any angle. To flip an image horizontally, add scale=-1 (though this is less common). The graphicx package handles both.

What if I want to put text on top of an image?

Use the tikz package with the \node command to overlay text. Alternatively, use the overpic package, which lets you place text at specific coordinates on top of an image. Both require a few extra lines of code but give you precise control over placement.

How do I make a diagram that shows connections between boxes?

TikZ is designed for this. Draw rectangles with \draw, then use \draw again to create lines between them. Add labels with \node. Flowchart examples are widely available online, and you can copy the structure and modify it for your own diagram.

Can I use images from the internet directly in LaTeX?

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

What happens if I delete the image file after I compile my document?

The image stays in the compiled PDF — it was embedded when you compiled. But if you edit the LaTeX file and compile again, LaTeX will look for the image file and fail if it is missing. Always keep your image files with your LaTeX source code.