> For the complete documentation index, see [llms.txt](https://overleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://overleaf-pro.ayaka.space/latex/figures-and-tables/02-positioning-images-and-tables.md).

# Positioning Images and Tables

LaTeX is an editing tool that takes care of the format so you only have to worry about the contents of your document; nevertheless, better control of floating elements is sometimes necessary. This article explains how to position images and tables in a LaTeX document.

## Introduction

The default alignment for images and tables is set to *left*

```latex
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisis sem. Nullam nec mi et neque pharetra
sollicitudin.

\includegraphics[width=0.5\textwidth]{overleaf-logo}

Praesent imperdiet mi nec
ante. Donec ullamcorper, felis non sodales commodo, lectus velit
ultrices augue, a dignissim nibh lectus placerat pede.
 Vivamus nunc nunc, molestie ut, ultricies
vel, semper in, velit. Ut porttitor.
```

![PositioningTnIEX1OverleafV2.png](/files/dqvTLK0d6yN8sY0X8g92)

This is a simple example, for a description of this and other ways to include images in your LaTeX file see the article [Inserting Images](/latex/more-topics/27-inserting-images.md).

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Positioning images

### Basic positioning

To change the default alignment of an image from *left* or *right*, an easy option is to add

```latex
\usepackage[export]{adjustbox}
```

to the preamble of your file and then use an additional option in your image-importing statement

```latex
Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
Etiam lobortis facilisis sem. Nullam nec mi et neque
pharetra sollicitudin.

\includegraphics[width=0.5\textwidth, right]{overleaf-logo}

Praesent imperdiet mi necante. Donec ullamcorper, felis
non sodales commodo, lectus velit ultrices augue,
a dignissim nibh lectus placerat pede. Vivamus nunc nunc,
molestie ut, ultriciesvel, semper in, velit. Ut porttitor.
```

![PositioningTnIEx2OLV2.png](/files/L84Kmw0d33Ij1sXxKqSV)

The package **adjustbox** enables an additional option in the `\includegraphics` command, in the example the picture is aligned to `right`. The available values are: *left*, *right*, *center*, *outer* and *inner*, the last two are intended for two-sided documents.

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

### The figure environment

The figure environment (see [Inserting Images](/latex/more-topics/27-inserting-images.md)) is intended to provide automatic positioning.

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet
ante lobortis sollicitudin.

\begin{figure}[h]
\includegraphics[width=0.5\textwidth, inner]{overleaf-logo}
\caption{Caption}
\label{fig:figure2}
\end{figure}
```

![PositioningTnIEx3OLV2.png](/files/K1VV6cq40AxXMtKAxoOc)

This environment uses a positioning parameter passed inside brackets, it can take the next values:

| Parameter | Position                                                                                                                          |
| --------- | --------------------------------------------------------------------------------------------------------------------------------- |
| h         | Place the float *here*, i.e., *approximately* at the same point it occurs in the source text (however, not *exactly* at the spot) |
| t         | Position at the *top* of the page.                                                                                                |
| b         | Position at the *bottom* of the page.                                                                                             |
| p         | Put on a special *page* for floats only.                                                                                          |
| !         | Override internal parameters LaTeX uses for determining "good" float positions.                                                   |
| H         | Places the float at precisely the location in the LaTeX code. Requires the `float` package. This is somewhat equivalent to h!.    |

You can put more than one value in the parameter, for instance, if you write `[ht]` LaTeX will try to position the figure **here**, but if it's not possible (the space may be insufficient) then the figure will appear at the **top** of the page. It is recommended to use more than one positioning parameter to prevent unexpected results.

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

### Multiple images in one figure

It is possible to insert several images in one figure, each one with its own reference and label

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque...

\begin{figure}[h]

\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=6cm]{overleaf-logo}
\caption{Caption1}
\label{fig:subim1}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
\includegraphics[width=0.9\linewidth, height=6cm]{mesh}
\caption{Caption 2}
\label{fig:subim2}
\end{subfigure}

\caption{Caption for this figure with two images}
\label{fig:image2}
\end{figure}

Praesent blandit blandit mauris. Praesent lectus tellus, aliquet aliquam, luctus a, egestas a, turpis. Mauris lacinia lorem sit amet ipsum. Nunc quis urna dictum turpis accumsan semper.
```

![PositioningTnIEx4OLV2.png](/files/WWuEUgdlbxWnyNSRtloS)

First, you must import the package **subcaption** by adding to the preamble

```latex
\usepackage{subcaption}
```

then you can use the environment `\subfigure` that takes one parameter, the width of the figure. This environment must be used inside a `figure` environment, captions and labels can be set to each *subfigure*.

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

### Wrapping text around a figure

The package **wrapfig** provides a useful feature, text can be floated around the images.

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat.

\begin{wrapfigure}{l}{0.25\textwidth}
\includegraphics[width=0.9\linewidth]{overleaf-logo}
\caption{Caption1}
\label{fig:wrapfig}
\end{wrapfigure}

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
```

![PositioningTnIEx5OLV2.png](/files/PxsrbHwSeK07jjEIEN7p)

First import the package *wrapfig* by adding

```latex
\usepackage{wrapfig}
```

to the preamble.

After that you can use the environment `wrapfig`, it takes two parameters that are passed inside braces: the alignement that can be *l*, *r*, *c*, *i* or *o*; this letters stand for left, right, centre, inner and outer (the last two intended for two-sided documents). The second parameter is the width of the figure, in the example is 0.25 the width of the text. See the [reference guide](#reference-guide) for a list of possible length units.

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

## Positioning tables

Options for table positioning are similar to those available for figures.

### Basic positioning

Default position of the tabular environment is *centre*.

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Duis fringilla tristique neque.
Sed interdum libero ut metus. Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit amet
ante lobortis sollicitudin.

\arrayrulecolor[HTML]{DB5800}
\begin{tabular}{ |s|p{2cm}|p{2cm}|  }
\hline
\rowcolor{lightgray} \multicolumn{3}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\hline
Afghanistan & AF &AFG \\
\rowcolor{gray}
Aland Islands & AX  & ALA \\
Albania    &AL & ALB \\
Algeria   &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & \cellcolor[HTML]{AA0044} AND \\
Angola & AO & AGO \\
\hline
\end{tabular}

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer adipiscing
elit. Duis fringilla tristique neque. Sed interdum libero ut metus.
Pellentesque placerat. Nam rutrum augue a leo. Morbi sed elit sit
amet ante lobortis sollicitudin.
```

&#x20;[Open this code fragment in Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=Default+position+of+tabular\&snip=%5Cdocumentclass%7Barticle%7D%0A%25Table-related+commands%0A%5Cusepackage%7Barray%7D%0A%5Cusepackage%5Btable%5D%7Bxcolor%7D%0A%5Csetlength%7B%5Carrayrulewidth%7D%7B1mm%7D%0A%5Csetlength%7B%5Ctabcolsep%7D%7B18pt%7D%0A%5Crenewcommand%7B%5Carraystretch%7D%7B1.5%7D%0A%5Cnewcolumntype%7Bs%7D%7B%3E%7B%5Ccolumncolor%5BHTML%5D%7BAAACED%7D%7D+p%7B3cm%7D%7D%0A%0A%5Cbegin%7Bdocument%7D%0APraesent+in+sapien.+Lorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+elit.+Duis+fringilla+tristique+neque.+%0ASed+interdum+libero+ut+metus.+Pellentesque+placerat.+Nam+rutrum+augue+a+leo.+Morbi+sed+elit+sit+amet+%0Aante+lobortis+sollicitudin.%0A%0A%5Carrayrulecolor%5BHTML%5D%7BDB5800%7D%0A%5Cbegin%7Btabular%7D%7B+%7Cs%7Cp%7B2cm%7D%7Cp%7B2cm%7D%7C++%7D%0A%5Chline%0A%5Crowcolor%7Blightgray%7D+%5Cmulticolumn%7B3%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A%5Chline%0ACountry+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+%5C%5C%0A%5Chline%0AAfghanistan+%26+AF+%26AFG+%5C%5C%0A%5Crowcolor%7Bgray%7D%0AAland+Islands+%26+AX++%26+ALA+%5C%5C%0AAlbania++++%26AL+%26+ALB+%5C%5C%0AAlgeria+++%26DZ+%26+DZA+%5C%5C%0AAmerican+Samoa+%26+AS+%26+ASM+%5C%5C%0AAndorra+%26+AD+%26+%5Ccellcolor%5BHTML%5D%7BAA0044%7D+AND+%5C%5C%0AAngola+%26+AO+%26+AGO+%5C%5C%0A%5Chline%0A%5Cend%7Btabular%7D%0A%0APraesent+in+sapien.+Lorem+ipsum+dolor+sit+amet%2C+consectetuer+adipiscing+%0Aelit.+Duis+fringilla+tristique+neque.+Sed+interdum+libero+ut+metus.+%0APellentesque+placerat.+Nam+rutrum+augue+a+leo.+Morbi+sed+elit+sit+%0Aamet+ante+lobortis+sollicitudin.%0A%5Cend%7Bdocument%7D)

The following graphic shows the result of the code fragment above:

![PositioningTnIEx6.png](/files/KFOWEenvgZb6N8VxfOJm)

You can also  [open a complete project example project in Overleaf.](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

To learn about how to create tables see the [Tables](/latex/figures-and-tables/01-tables.md) article.

### The table environment

The table environment is intended to automatically position tables so they fit nicely in the flow of your document.

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.

\begin{table}[ht]
\arrayrulecolor[HTML]{DB5800}
\centering
\begin{tabular}{ |s|p{2cm}|p{2cm}|  }
\hline
\rowcolor{lightgray} \multicolumn{3}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code &ISO ALPHA 3 \\
\hline
Afghanistan & AF &AFG \\
\rowcolor{gray}
Aland Islands & AX  & ALA \\
Albania    &AL & ALB \\
Algeria   &DZ & DZA \\
American Samoa & AS & ASM \\
Andorra & AD & \cellcolor[HTML]{AA0044} AND \\
Angola & AO & AGO \\
\hline
\end{tabular}
\caption{Table inside a floating element}
\label{table:ta}
\end{table}

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.
```

&#x20;[Open this code fragment in Overleaf](https://www.overleaf.com/docs?engine=\&snip_name=Default+position+of+tabular\&snip=%5Cdocumentclass%7Barticle%7D%0A%25Table-related+commands%0A%5Cusepackage%7Barray%7D%0A%5Cusepackage%5Btable%5D%7Bxcolor%7D%0A%5Csetlength%7B%5Carrayrulewidth%7D%7B1mm%7D%0A%5Csetlength%7B%5Ctabcolsep%7D%7B18pt%7D%0A%5Crenewcommand%7B%5Carraystretch%7D%7B1.5%7D%0A%5Cnewcolumntype%7Bs%7D%7B%3E%7B%5Ccolumncolor%5BHTML%5D%7BAAACED%7D%7D+p%7B3cm%7D%7D%0A%0A%5Cbegin%7Bdocument%7D%0APraesent+in+sapien.+Lorem+ipsum+dolor+sit+amet%2C+consectetuer+%0Aadipiscing+elit.+Duis+fringilla+tristique+neque.+Sed+interdum+%0Alibero+ut+metus.+Pellentesque+placerat.+Nam+rutrum+augue+a+leo.%0AMorbi+sed+elit+sit+amet+ante+lobortis+sollicitudin.%0A%0A%5Cbegin%7Btable%7D%5Bht%5D%0A%5Carrayrulecolor%5BHTML%5D%7BDB5800%7D%0A%5Ccentering%0A%5Cbegin%7Btabular%7D%7B+%7Cs%7Cp%7B2cm%7D%7Cp%7B2cm%7D%7C++%7D%0A%5Chline%0A%5Crowcolor%7Blightgray%7D+%5Cmulticolumn%7B3%7D%7B%7Cc%7C%7D%7BCountry+List%7D+%5C%5C%0A%5Chline%0ACountry+Name+or+Area+Name%26+ISO+ALPHA+2+Code+%26ISO+ALPHA+3+%5C%5C%0A%5Chline%0AAfghanistan+%26+AF+%26AFG+%5C%5C%0A%5Crowcolor%7Bgray%7D%0AAland+Islands+%26+AX++%26+ALA+%5C%5C%0AAlbania++++%26AL+%26+ALB+%5C%5C%0AAlgeria+++%26DZ+%26+DZA+%5C%5C%0AAmerican+Samoa+%26+AS+%26+ASM+%5C%5C%0AAndorra+%26+AD+%26+%5Ccellcolor%5BHTML%5D%7BAA0044%7D+AND+%5C%5C%0AAngola+%26+AO+%26+AGO+%5C%5C%0A%5Chline%0A%5Cend%7Btabular%7D%0A%5Ccaption%7BTable+inside+a+floating+element%7D%0A%5Clabel%7Btable%3Ata%7D%0A%5Cend%7Btable%7D%0A%0APraesent+in+sapien.+Lorem+ipsum+dolor+sit+amet%2C+consectetuer+%0Aadipiscing+elit.+Duis+fringilla+tristique+neque.+Sed+interdum+%0Alibero+ut+metus.+Pellentesque+placerat.+Nam+rutrum+augue+a+leo.+%0AMorbi+sed+elit+sit+amet+ante+lobortis+sollicitudin.%0A%5Cend%7Bdocument%7D)

The following graphic shows the output produced by the Overleaf link:

![PositioningTnIEx7.png](/files/ckEBmlu7PiM8SbmCrUiq)

A position parameter, inside brackets, can be passed to the **table** environment. This parameter can take the next values:

| Parameter | Position                                                                                                                          |
| --------- | --------------------------------------------------------------------------------------------------------------------------------- |
| h         | Place the float *here*, i.e., *approximately* at the same point it occurs in the source text (however, not *exactly* at the spot) |
| t         | Position at the *top* of the page.                                                                                                |
| b         | Position at the *bottom* of the page.                                                                                             |
| p         | Put on a special *page* for floats only.                                                                                          |
| !         | Override internal parameters LaTeX uses for determining "good" float positions.                                                   |
| H         | Places the float at precisely the location in the LaTeX code. Requires the `float` package. This is somewhat equivalent to h!.    |

You can set more than one value in the parameter, for instance, if you write `[ht]` LaTeX will try to position the table **here**, but if it's not possible (the space may be insufficient) then the table will appear at the **top** of the page. It is recommended to use more than one positioning parameter to prevent unexpected results.

Notice also the command `\centering`. This changes the alignment of the table within its container to *centre* instead of the default *left*.

&#x20;[Open an example in Overleaf](https://www.overleaf.com/project/new/template/19663?id=66518064\&templateName=Example+of+positioning+tables+and+figures\&latexEngine=pdflatex\&texImage=texlive-full%3A2020.1\&mainFile=)

### Wrapping text around a table

If your table don't take all available space and you want to put text next or before it, is possible with the package `wrapfig`.

First, import the package

```latex
\usepackage{wrapfig}
```

then you can use the environment `wraptable` which takes two parameters: The first one is the alignment that can be `l`, `r`, `c`, `i` or `o` for left, right, centre, inner and outer respectively. The second one is the width of the table container, keep in mind that this latter parameter must be the same as the width of the table, otherwise things may not be properly aligned.

```latex
Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin.

\begin{wraptable}{r}{8cm}
\arrayrulecolor[HTML]{DB5800}
\centering
\begin{tabular}{ |s|p{2cm}|  }
\hline
\rowcolor{lightgray} \multicolumn{2}{|c|}{Country List} \\
\hline
Country Name or Area Name& ISO ALPHA 2 Code \\
\hline
Afghanistan & AF \\
\rowcolor{gray}
Aland Islands & AX \\
Albania    &AL  \\
Algeria   &DZ \\
American Samoa & AS \\
Andorra & \cellcolor[HTML]{AA0044} AD   \\
Angola & AO \\
\hline
\end{tabular}
\caption{Table inside a wraptable}
\label{table:ta2}
\end{wraptable}

Praesent in sapien. Lorem ipsum dolor sit amet, consectetuer
adipiscing elit. Duis fringilla tristique neque. Sed interdum
libero ut metus. Pellentesque placerat. Nam rutrum augue a leo.
Morbi sed elit sit amet ante lobortis sollicitudin...
```

&#x20;Open this `wrapfig` code fragment in Overleaf

The following graphic shows the output produced by the Overleaf link:

![PositioningTnIEx8OLV2.png](/files/j2iZaXgr2ZfupWl3dlJZ)

## Reference guide

**LaTeX units and lengths**

| Abbreviation | Definition                                          |
| ------------ | --------------------------------------------------- |
| pt           | A point, is the default length unit. About 0.3515mm |
| mm           | a millimetre                                        |
| cm           | a centimetre                                        |
| in           | an inch                                             |
| ex           | the height of an **x** in the current font          |
| em           | the width of an **m** in the current font           |
| \columnsep   | distance between columns                            |
| \columnwidth | width of the column                                 |
| \linewidth   | width of the line in the current environment        |
| \paperwidth  | width of the page                                   |
| \paperheight | height of the page                                  |
| \textwidth   | width of the text                                   |
| \textheight  | height of the text                                  |
| \unitlength  | units of length in the *picture* environment.       |

## Further reading

For more information see:

* [Tables](/latex/figures-and-tables/01-tables.md)
* [Inserting Images](/latex/more-topics/27-inserting-images.md)
* [Lists of tables and figures](/latex/figures-and-tables/03-lists-of-tables-and-figures.md)
* [Lengths in LaTeX](/latex/formatting/01-lengths-in-latex.md)
* [**floatrow** package for advanced caption managing of floating elements (tables and figures)](http://tug.ctan.org/tex-archive/macros/latex/contrib/floatrow/floatrow.pdf)
* [**sidecap** package documentation, for side-figure captions](ftp://ctan.tug.org/tex-archive/macros/latex/contrib/sidecap/sidecap.pdf)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://overleaf-pro.ayaka.space/latex/figures-and-tables/02-positioning-images-and-tables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
