> For the complete documentation index, see [llms.txt](https://ayakaleaf-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://ayakaleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/50-wrapping-text-around-figures.md).

# 让文字环绕图形

有时，可能希望让文本环绕一个浮动体（在这里是一个图形），以免打断文本的流动。在 LaTeX 中有不少宏包可以完成这项任务，不过在大多数情况下都需要一定程度的手动调整。

### 使用 wrapfig

要使用 *wrapfig*，我们需要在导言区包含以下一行：

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

这使得 *wrapfigure* 环境可供我们使用，我们可以在其中放入一个 *\includegraphics* 命令来创建一个让文本环绕的图形。下面是我们如何指定一个 *wrapfigure* 环境：

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

该 *位置* 参数有八种可能的取值：

|   |   |                                |
| - | - | ------------------------------ |
| r | R | 文本右侧                           |
| l | L | 文本左侧                           |
| i | I | 内侧边缘——靠近装订处（在一个 *twoside* 文档中） |
| 或 | O | 外侧边缘——远离装订处                    |

大写版本允许图形浮动。小写版本表示 *就在这里*.

下面是一个示例：

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

可以注意到，所包含图像的宽度是相对于文本宽度（*\textwidth*）来指定的。使用相对尺寸来定义长度（高度、宽度等）是个好主意，尤其是在使用 *wrapfigure*.

在上面的例子中，图形正好占据了文本宽度的一半，而实际图像使用了稍小一点的宽度，因此图像与文本之间会留出一个赏心悦目的小白边。图像应始终小于（不那么宽于）环绕区域，否则它会覆盖到正文。

在添加 *wrapfigures* 时要特别小心，尤其是将其放在页面顶部或底部附近，因为这常常会导致难以解决甚至几乎无法解决的非预期效果。不建议尝试在 *wrapfigures* 方程或节标题旁边使用它们。它们也不能用于列表中，例如 `itemize` 和 `enumerate` 环境中的内容。

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

### 处理带有空白的图像

如果图像有不需要的空白，我们可以使用以下任一选项来移除多余的空白：

* *裁剪* 在使用 \includegraphics 时裁剪空白
* 该 *picins* 包可用于替代 *wrapfigure*，它无需任何手动调整即可开箱即用地去除多余空白。
* 包 *floatflt* 是另一种替代方案。
* 避免使用 *\begin{center}* 来居中图像，因为这会增加额外空白。使用 *\centering* 。
* 程序 *pdfcrop* （大多数 TeX 安装中都包含）可用于永久移除空白。


---

# 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://ayakaleaf-pro.ayaka.space/latex/zh-cn/geng-duo-zhu-ti/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.
