# LaTeX code for including images in your document

{% hint style="info" %}
In these instructions, it is assumed that your image has already been uploaded to your Overleaf project.
{% endhint %}

This page explains how to include images in the most common formats, how to shrink, enlarge and rotate them, and how to reference them within your document. We will start with an example to demonstrate how to import a picture.

```latex
\documentclass{article}
\usepackage{graphicx}
\graphicspath{ {./images/} }

\begin{document}
The universe is immense and it seems to be homogeneous, 
in a large scale, everywhere we look at.

\includegraphics{universe}

There's a picture of a galaxy above
\end{document}
```

<figure><img src="/files/2bvpr11AuP42n5lbSsT5" alt="Example of inserting an image"><figcaption></figcaption></figure>

LaTeX cannot manage images by itself, so we need to use the `graphicx` package. To use it, we include the following line in the preamble: `\usepackage{graphicx}`.

The command `\graphicspath{ {./images/} }` tells LaTeX that the images are kept in a folder named `images` under the directory of the main document.

The `\includegraphics{universe}` command is the one that actually includes the image in the document. Here `universe` is the name of the file containing the image without the extension, then `universe.PNG` becomes `universe`. The file name of the image should not contain white spaces nor multiple dots.

{% hint style="warning" %}
The file extension is allowed to be included, but it's a good idea to omit it. If the file extension is omitted it will prompt LaTeX to search for all the supported formats. For more details see the section about [generating high resolution and low resolution images](/writing-and-editing/inserting-images.md#generating-high-res-and-low-res-images).
{% endhint %}

[Open an images example in Overleaf](https://www.overleaf.com/project/new/template/19397?id=65443742\&templateName=Inserting+Images\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## The folder path to images

When working on a document which includes several images, it's possible to keep those images in one or more separated folders so that your project is more organized.

The command `\graphicspath{ {images/} }` tells LaTeX to look in the `images` folder. The path is ***relative*** to the current working directory—so, the compiler will look for the file in the same folder as the code where the image is included. The path to the folder is relative by default, if there is no initial directory specified, for instance

```latex
%Path relative to the .tex file containing the \includegraphics command
\graphicspath{ {images/} }
```

This is a typically straightforward way to reach the graphics folder within a file tree, but can leads to complications when `.tex` files within folders are included in the main `.tex` file. Then, the compiler may end up looking for the images folder in the wrong place. Thus, **it is best practice to specify the graphics path to be relative to the main `.tex` file**, denoting the main `.tex` file directory as `./` , for instance:

```latex
%Path relative to the main .tex file 
\graphicspath{ {./images/} }
```

as in the introduction.

The path can also be ***absolute***, if the exact location of the file on your system is specified. For example, if you were working on a local LaTeX installation on your own computer:

```latex
%Path in Windows format:
\graphicspath{ {c:/user/images/} }

%Path in Unix-like (Linux, Mac OS) format
\graphicspath{ {/home/user/images/} }
```

Notice that this command requires a trailing slash `/` and that the path is in between double braces.

You can also set multiple paths if the images are saved in more than one folder. For instance, if there are two folders named `images1` and `images2`, use the command:

```latex
\graphicspath{ {./images1/}{./images2/} }
```

[Open an images example in Overleaf](https://www.overleaf.com/project/new/template/19397?id=65443742\&templateName=Inserting+Images\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

For additional information on some of the options that are available for the \includegraphics command, see [Advanced LaTeX image topics](/writing-and-editing/inserting-images/advanced-latex-image-topics.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overleaf.com/writing-and-editing/inserting-images/latex-code-for-including-images-in-your-document.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
