> 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/more-topics/50-wrapping-text-around-figures.md).

# Wrapping text around figures

At times, it might be desirable to wrap text around a float (a figure, in our case) so as not to break the flow of the text. There are a number of packages in LaTeX to accomplish this task, though they require some amount of manual tuning in most of the cases.

### Using wrapfig

To use *wrapfig*, we need to include the following line in preamble:

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

This makes the *wrapfigure* environment available to us, and we can put a *\includegraphics* command inside it to create a figure around which text will be wrapped. Here is how we can specify a *wrapfigure* environment:

```latex
\begin{wrapfigure}[lineheight]{position}{width}
  ...
\end{wrapfigure}
```

The *position* parameter has eight possible values:

|   |   |                                                        |
| - | - | ------------------------------------------------------ |
| r | R | right side of the text                                 |
| l | L | left side of the text                                  |
| i | I | inside edge–near the binding (in a *twoside* document) |
| o | O | outside edge–far from the binding                      |

The uppercase version allows the figure to float. The lowercase version means *exactly here*.

Here is an example:

```latex
\begin{wrapfigure}{r}{0.5\textwidth}
  \begin{center}
    \includegraphics[width=0.48\textwidth]{birds}
  \end{center}
  \caption{Birds}
\end{wrapfigure}
```

It may be noted that the width of the image included was specified relative to width of the text (*\textwidth*). It is a good idea to use relative sizes to define lengths (height, width, etc), particularly when using *wrapfigure*.

In the example above, the figure covers exactly half of the the textwidth, and the actual image uses a slightly smaller width, so that there is a pleasing small white frame between the image and the text. The image should always be smaller (less wide) than the wrap, or it will overrun the text.

Take care while using adding *wrapfigures* very near the top or bottom of a page, as this can often cause unwanted effects that are hard or near-impossible to solve. It is not advisable to try to use *wrapfigures* alongside equations or sectional headers. They also cannot be used in lists, such as `itemize` and `enumerate` environments.

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

### Dealing with Images with white space

In case the image has undesirable white space, we can use any of the following options to remove the extra whitespace:

* *trim* the white space when using \includegraphics
* The *picins* package may be used instead of *wrapfigure*, which removes the extra white space out of the box without any manual tuning.
* The package *floatflt* is another alternative.
* Avoid using *\begin{center}* to center the image, it adds extra space. Use *\centering* instead.
* The program *pdfcrop* (included in most TeX installations) may be used to remove the white space permanently.


---

# 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/more-topics/50-wrapping-text-around-figures.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.
