> 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/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}
```

该 *position* 参数有八种可能的值：

|   |   |                               |
| - | - | ----------------------------- |
| 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{鸟类}
\end{wrapfigure}
```

需要注意，所包含图像的宽度是相对于文本宽度（*\textwidth*）来指定的。最好使用相对大小来定义长度（高度、宽度等），尤其是在使用 *wrapfigure*.

在上面的示例中，图形正好占据文本宽度的一半，而实际图像使用的宽度略小一些，因此图像与文本之间会留出一小块赏心悦目的白边。图像应始终比环绕区域更小（更窄），否则就会覆盖到文本上。

在添加时要小心 *wrapfigures* ，尤其是在页面顶部或底部附近，因为这常常会导致难以解决、甚至几乎无法解决的不良效果。不建议尝试将 *wrapfigures* 与公式或章节标题一起使用。它们也不能用于列表中，例如 `itemize` 和 `enumerate` 环境。

&#x20;[在 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://overleaf-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.
