The basic command to add a picture in LaTeX

To add a picture in LaTeX, you use the \includegraphics command inside the document body. The simplest version looks like this:

\includegraphics{filename.jpg}

This command tells LaTeX to find the image file in your project folder and insert it at that location in your document. The image will appear at its original size. You need to have the graphicx package loaded in your preamble (the section before \begin{document}) by writing \usepackage{graphicx} near the top of your file.

The filename can be a JPG, PNG, PDF, or other common image format. If the file is in a subfolder, include the path: \includegraphics{images/filename.jpg}.

Key Takeaways

  • Add \usepackage{graphicx} to your preamble before you can use the \includegraphics command.
  • The basic syntax is \includegraphics{filename}, and the file must be in your project folder or in a subfolder you specify.
  • Control image size with the width or height option: \includegraphics[width=5cm]{filename}.
  • Wrap images in a figure environment to add captions, labels, and positioning control.

Resizing images to fit your page

By default, \includegraphics inserts the image at full size, which often means it runs off the page. Use square brackets after the command to add options that control the size.

To set the width, write \includegraphics[width=5cm]{filename}. You can use centimeters (cm), inches (in), or a fraction of the page width like 0.8\textwidth. If you set only the width, LaTeX automatically scales the height to keep the image proportional.

To set the height instead, use \includegraphics[height=4cm]{filename}. You can also set both, though this may stretch or squash the image if the proportions do not match: \includegraphics[width=5cm, height=4cm]{filename}.

A common approach is to make the image 80 percent of the page width: \includegraphics[width=0.8\textwidth]{filename}. This keeps the image readable while leaving room for text on most page sizes.

Adding captions and labels with the figure environment

If you want a caption, a number, or the ability to reference the image elsewhere in your document, wrap the \includegraphics command in a figure environment. This also gives you control over where LaTeX places the image on the page.

A basic figure looks like this:

\begin{figure}[h] \includegraphics[width=0.7\textwidth]{filename} \caption{This is the caption that appears below the image} \label{fig:myimage} \end{figure}

The [h] tells LaTeX to place the figure "here" on the page. Other options are [t] for top of page, [b] for bottom, and [p] for a dedicated page of figures. LaTeX will try to honor your choice but may move the figure if it does not fit.

The \caption command adds text below the image and automatically numbers it (Figure 1, Figure 2, and so on). The \label command lets you reference this figure elsewhere by writing \ref{fig:myimage}, which will print the correct number even if you add or remove figures later.

Centering images on the page

By default, images align to the left margin. To center an image, wrap it in a center environment:

\begin{center} \includegraphics[width=5cm]{filename} \end{center}

If the image is inside a figure environment, put the center environment inside the figure:

\begin{figure}[h] \begin{center} \includegraphics[width=0.6\textwidth]{filename} \end{center} \caption{A centered image} \end{figure}

Centering works well for images that are the focus of a section. For images that sit alongside text, you may want to use a two-column layout instead, which is more complex but gives you finer control.

Rotating and flipping images

To rotate an image, add the angle option to \includegraphics. The angle is measured in degrees, and positive numbers rotate counterclockwise:

\includegraphics[width=5cm, angle=90]{filename}

This rotates the image 90 degrees. You can use any number: 45 for a 45-degree tilt, 180 to flip the image upside down, or 270 to rotate three-quarters of the way around.

LaTeX does not have a built-in flip command, but you can achieve a horizontal flip by rotating 180 degrees and then rotating back, or by using the graphicx package's scale option with a negative value: \includegraphics[scale=-1]{filename}. However, this approach is less reliable across different LaTeX systems, so rotation is usually the safer choice.

Troubleshooting common image problems

If LaTeX cannot find your image, check that the filename matches exactly (including capitalization and file extension) and that the file is in your project folder or in the path you specified. LaTeX is case-sensitive on most systems, so Photo.jpg and photo.jpg are different files.

If the image appears blurry or pixelated, the original file may be too small or low-resolution. For photographs, use JPG format. For diagrams and screenshots, PNG usually works better because it does not compress as aggressively. PDF images are also supported and work well for vector graphics.

If the image is too large and pushes text off the page, use the width or height option to scale it down. If LaTeX places the image on a different page than you expected, try changing the position option in the figure environment from [h] to [!h] (the exclamation mark tells LaTeX to override its usual placement rules, though it still may not work if the image is very large).

Frequently Asked Questions

What image formats does LaTeX support?

LaTeX supports JPG, PNG, PDF, and several other formats. JPG works well for photographs. PNG is better for diagrams, charts, and screenshots because it preserves sharp edges. PDF is useful if you have vector graphics or want to include a page from another PDF document.

Can I add text or labels on top of an image?

Yes, but it requires the tikz or overpic package, which are more advanced. For simple captions, use the \caption command inside the figure environment. For overlaid text, you will need to learn TikZ syntax or use an image editor to add the text before inserting the image into LaTeX.

How do I place an image next to text instead of on its own line?

Use the wrapfig package and the wrapfigure environment instead of figure. This lets text flow around the image. Add \usepackage{wrapfig} to your preamble, then write \begin{wrapfigure}{r}{5cm} to place the image on the right with text wrapping around it on the left.

Why does my image look different in the PDF than in my editor?

Your editor may show a preview that is not perfectly accurate. Always compile your LaTeX document to PDF to see the final result. Image quality, size, and positioning may differ slightly between the preview and the compiled PDF.