# Advanced LaTeX image topics

## Commonly used LaTeX units and lengths

When including images using the `\includegraphics` command, it is sometimes required to provide measurements and length when adjusting the size or positioning. The table below summarizes some of the most frequently used LaTeX units and lengths.

<table><thead><tr><th width="153.00390625">Unit or length</th><th>Definition</th></tr></thead><tbody><tr><td><code>pt</code></td><td>the default length unit, about 0.3515mm</td></tr><tr><td><code>mm</code></td><td>a millimeter</td></tr><tr><td><code>cm</code></td><td>a centimeter</td></tr><tr><td><code>in</code></td><td>an inch</td></tr><tr><td><code>ex</code></td><td>the height of an x in the current font</td></tr><tr><td><code>em</code></td><td>the width of an m in the current font</td></tr><tr><td><code>\columnsep</code></td><td>distance between columns</td></tr><tr><td><code>\columnwidth</code></td><td>width of the column</td></tr><tr><td><code>\linewidth</code></td><td>width of the line in the current environment</td></tr><tr><td><code>\paperwidth</code></td><td>width of the page</td></tr><tr><td><code>\paperheight</code></td><td>height of the page</td></tr><tr><td><code>\textwidth</code></td><td>width of the text</td></tr><tr><td><code>\textheight</code></td><td>height of the text</td></tr><tr><td><code>\unitlength</code></td><td>units of length in the <em>picture</em> environment</td></tr></tbody></table>

## Compilers and image types

**latex**

When compiling with "latex", you can only use EPS images, which are a vector format.

**pdflatex**

If you are compiling using "pdflatex" to produce a PDF, then you can use a number of image formats:

```latex
JPG: Best choice to insert photos
PNG: Best choice to insert diagrams (if a vector version could not be generated) and screenshots
PDF: Even though we are used to seeing PDF documents, a PDF can also store images 
EPS: EPS images can be included using the epstopdf package (you just need to install the package, you 
        don't need to use \usepackage{} to include it in your document.)
```

**Vector format or bitmap format?**

Images can be in either vector format or bitmap format. Generally you don't need to worry about it, but if you do happen to know the format the image is in, you can use that information to choose an appropriate image format to include in your LaTeX document. If you have an image in vector format, you should go for PDF or EPS. If you have it in bitmap format, you should go for JPG or PNG, as storing bitmap pictures in PDF or EPS takes a lot of disk space.

[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=)

## Providing high-res and low-res images

So far while specifying the image file name in the `\includegraphics` command, we have omitted file extensions. However, that is not necessary, though it is often useful. If the file extension is omitted, LaTeX will search for any supported image format in that directory, and will search for various extensions in the default order (which can be modified).

This is useful in switching between development and production environments. In a development environment (when the article/report/book is still in progress), it is desirable to use low-resolution versions of images (typically in .png format) for fast compilation of the preview. In the production environment (when the final version of the article/report/book is produced), it is desirable to include the high-resolution version of the images.

This is accomplished by:

* Not specifying the file extension in the *\includegraphics* command, and
* Specifying the desired extension in the preamble.

Thus, if we have two versions of an image, venndiagram.pdf (high-resolution) and venndiagram.png (low-resolution), then we can include the following line in the preamble to use the .png version while developing the report:

```latex
  \DeclareGraphicsExtensions{.png,.pdf}
```

The command above will ensure that if two files are encountered with the same base name but different extensions (e.g., venndiagram.pdf and venndiagram.png), then the .png version will be used first, and in its absence the .pdf version will be used. This is also a good idea if some low-resolution versions are not available.

Once the report has been developed, to use the high-resolution .pdf version, we can change the line in the preamble specifying the extension search order to:

```latex
  \DeclareGraphicsExtensions{.pdf,.png}
```

Improving on the technique described in the previous paragraphs, we can also instruct LaTeX to generate low-resolution .png versions of images on the fly while compiling the document if there is a PDF that has not been converted to PNG yet. To achieve that, we can include the following in the preamble after: `\usepackage{graphicx}`

```latex
  \usepackage{epstopdf}
  \epstopdfDeclareGraphicsRule{.pdf}{png}{.png}{convert #1 \OutputFile}
  \DeclareGraphicsExtensions{.png,.pdf}
```

If venndiagram2.pdf exists but not venndiagram2.png, the file venndiagram2-pdf-converted-to.png will be created and loaded in its place. The command *convert #1* is responsible for the conversion and additional parameters may be passed between *convert* and *#1*. For example: *convert -density 100 #1*.

There are some important things to keep in mind though:

* For the automatic conversion to work, you need to call *pdflatex* with the `--shell-escape` option.
* For the final *production* version, you must comment out the `\epstopdfDeclareGraphicsRule`, so that only high-resolution PDF files are loaded. You'll also need to change the order of precedence.

[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=)

## Further reading

For more information see:

* [Positioning images and tables](https://learn.overleaf.com/learn/Positioning_images_and_tables)
* [Lists of tables and figures](https://learn.overleaf.com/learn/Lists_of_tables_and_figures)
* [Single sided and double sided documents](https://learn.overleaf.com/learn/Single_sided_and_double_sided_documents)
* [Lengths in LaTeX](https://learn.overleaf.com/learn/Lengths_in_LaTeX)
* [floatrow package for advanced caption managing of floating elements (tables and figures)](https://texdoc.org/serve/floatrow/0)
* [sidecap package documentation, for side-figure captions](ftp://ctan.tug.org/tex-archive/macros/latex/contrib/sidecap/sidecap.pdf)
* [**epstopdf** package documentation (EPS to PDF conversion)](https://ctan.org/pkg/epstopdf?lang=en)


---

# 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/advanced-latex-image-topics.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.
