Adding figures in LaTeX means placing image files into your document and controlling where they appear on the page
LaTeX treats figures as objects you can position, caption, and reference by number — unlike pasting an image directly into a word processor. To add a figure, you use the graphicx package to load images, wrap them in a figure environment to make them float to the best position on the page, and add captions and labels so you can refer to them in your text.
The basic steps are: load the graphicx package in your preamble, use the \includegraphics command to insert the image file, place it inside a figure environment with \begin{figure} and \end{figure}, add a caption with \caption{}, and label it with \label{} so you can reference it later using \ref{}.
Key Takeaways
- Add \usepackage{graphicx} to your document preamble before \begin{document} to enable image insertion.
- Use \includegraphics[width=0.5\textwidth]{filename} to insert an image and control its size relative to your page width.
- Wrap images in a figure environment with \begin{figure} and \end{figure} to let LaTeX position them automatically and add captions.
- Add \caption{} and \label{} inside the figure environment so LaTeX numbers your figures and you can reference them with \ref{fig:label}.
- Place the image file in the same folder as your .tex document, or specify the full path in the filename.
Loading the graphicx package
Before you can insert any images, you must tell LaTeX to load the graphicx package. This package provides the commands you need to include and scale images. Add this line to your document preamble — the section between \documentclass{} and \begin{document}:
\usepackage{graphicx}
The preamble is where you load all packages and set up your document. If you already have other \usepackage lines, add graphicx alongside them. You only need to load it once per document.
The basic \includegraphics command
The \includegraphics command inserts an image file into your document. The simplest form is:
\includegraphics{myimage.png}
Replace myimage.png with the actual filename of your image. LaTeX will insert the image at its original size. If the image is too large or too small, you can scale it using the width or height option:
\includegraphics[width=0.5\textwidth]{myimage.png}
This makes the image half the width of your text area. You can also use \includegraphics[height=3cm]{myimage.png} to set a specific height in centimeters, or \includegraphics[scale=0.7]{myimage.png} to scale it to 70 percent of its original size. If you set only width or height, LaTeX keeps the image's proportions so it does not stretch or squash.
Using the figure environment to add captions and positioning
Placing \includegraphics directly in your text will insert the image exactly where you typed it, which often leaves awkward gaps on the page. The figure environment tells LaTeX to treat the image as a floating object — it can move up or down slightly to fit better with your text. Wrap your image in \begin{figure} and \end{figure}:
\begin{figure} \includegraphics[width=0.6\textwidth]{myimage.png} \caption{This is the caption that appears below the image} \label{fig:mylabel} \end{figure}
The \caption{} command adds a numbered caption below the image. LaTeX automatically numbers figures as Figure 1, Figure 2, and so on. The \label{} command gives the figure a name you can use to reference it later in your text — use a descriptive label like fig:results or fig:diagram so you remember what it is.
By default, figures float to the top of the page or the next page. If you want more control over positioning, add an option after \begin{figure}:
\begin{figure}[h] \includegraphics[width=0.6\textwidth]{myimage.png} \caption{Caption text} \label{fig:mylabel} \end{figure}
The [h] option tells LaTeX to place the figure "here" — roughly where you typed it. Other options are [t] for top of page, [b] for bottom, and [p] for a page of floats. You can combine them, like [htp], to give LaTeX multiple preferences in order.
Referencing figures in your text
Once you have labeled a figure with \label{fig:mylabel}, you can refer to it by number anywhere in your document using \ref{fig:mylabel}. For example:
As shown in Figure \ref{fig:results}, the data increases over time.
LaTeX automatically replaces \ref{fig:results} with the correct figure number. If you later add or remove figures, all the numbers update automatically — you do not have to renumber them by hand. This is one of the main advantages of using labels and references instead of typing "Figure 3" directly into your text.
Centering images and adjusting spacing
By default, images inside a figure environment are left-aligned. To center an image, wrap the \includegraphics command in a \centering command:
\begin{figure} \centering \includegraphics[width=0.6\textwidth]{myimage.png} \caption{Centered image caption} \label{fig:centered} \end{figure}
If you want extra space above or below the image, use \vspace{} before or after the \includegraphics line. For example, \vspace{0.5cm} adds half a centimeter of space. You can also adjust spacing between the image and caption by adding \vspace{} between them.
If you have multiple images side by side, use the minipage environment to divide the space:
\begin{figure} \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\textwidth]{image1.png} \caption{First image} \label{fig:first} \end{minipage} \hfill \begin{minipage}{0.45\textwidth} \centering \includegraphics[width=\textwidth]{image2.png} \caption{Second image} \label{fig:second} \end{minipage} \end{figure}
This creates two columns, each taking up 45 percent of the text width, with space between them. Each minipage can have its own caption and label.
File paths and image formats
LaTeX looks for image files in the same folder as your .tex document by default. If your image is in a subfolder, specify the path:
\includegraphics[width=0.6\textwidth]{images/myimage.png}
This tells LaTeX to look in a folder named images inside your document folder. Use forward slashes even on Windows. If you want to tell LaTeX to always look in a specific folder, add this line to your preamble:
\graphicspath{{images/}{figures/}}
LaTeX supports common image formats: PNG, JPG, PDF, and EPS. PDF images work especially well in LaTeX because they scale smoothly without losing quality. If you are compiling with pdflatex (the most common method), avoid EPS files — convert them to PDF first using a tool like ImageMagick or Ghostscript.
Frequently Asked Questions
What happens if LaTeX cannot find my image file?
LaTeX will show an error message saying the file is not found. Check that the filename and path are spelled correctly, including the file extension (.png, .jpg, etc.). Make sure the image is actually in the folder you specified. If you are using a relative path like images/myimage.png, the images folder must be in the same location as your .tex file.
Can I rotate or flip an image in LaTeX?
Yes, add the angle option to \includegraphics: \includegraphics[width=0.6\textwidth,angle=90]{myimage.png} rotates the image 90 degrees clockwise. You can use any angle. To flip an image horizontally, add scale=-1 to the width: \includegraphics[width=-0.6\textwidth]{myimage.png}.
How do I add a border or frame around an image?
Wrap the \includegraphics command in a \fbox command: \fbox{\includegraphics[width=0.6\textwidth]{myimage.png}}. This adds a simple black border. For more control over the border style, load the fancybox package and use \shadowbox{} or \ovalbox{} instead.
Why is my figure appearing on a different page than where I typed it?
The figure environment floats — LaTeX moves it to find the best position on the page. If you want it to stay exactly where you typed it, use [h!] instead of [h]: \begin{figure}[h!]. The exclamation mark tells LaTeX to override its usual positioning rules, though this can sometimes create awkward spacing.
Can I have a caption above the image instead of below?
Yes, move the \caption{} command before the \includegraphics command: \begin{figure} \caption{Caption above} \includegraphics[width=0.6\textwidth]{myimage.png} \end{figure}. The caption will appear above the image instead of below.