> 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-tw/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 | O | 外側邊緣——遠離裝訂處                  |

大寫版本允許圖形浮動。小寫版本表示 *就在這裡*.

以下是一個範例：

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

可以注意到，所包含圖片的寬度是相對於文字寬度（*\textwidth*）。在定義長度（高度、寬度等）時使用相對尺寸是個好主意，特別是在使用 *wrapfigure*.

在上面的範例中，該圖正好佔據文字寬度的一半，而實際圖片使用稍小一點的寬度，這樣圖片與文字之間就會有一道令人舒服的小白邊。圖片應該總是比 wrap 區域更小（更窄），否則它會超出文字範圍。

在加入時請小心 *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://overleaf-pro.ayaka.space/latex/zh-tw/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.
