> 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/zhi-shi-ku/075-how-to-paste-formatted-content-into-overleaf.md).

# 如何将格式化内容粘贴到 Overleaf

*请注意：粘贴带格式内容是一项新功能，我们正在持续改进，以确保它能在多种场景下良好运行。我们也非常希望听到你对它的反馈，你可以在* [*本次调查*](https://docs.google.com/forms/d/e/1FAIpQLSc7WcHrwz9fnCkUP5hXyvkG3LkSYZiR3lVJWZ0o6uqNQYrV7Q/viewform)*.*

你可以粘贴带格式内容，包括 [表格](#pasting-tables-into-your-overleaf-project), [images](#pasting-images-into-your-overleaf-project), [带样式的文本](#pasting-styled-text-into-your-overleaf-project)以及 [列表](#pasting-lists-into-your-overleaf-project) 到我们的 **可视化编辑器** 中，并使用 Ctrl+V（在 Windows/Linux 上）或 Cmd+V（在 MacOS 上）保留格式。

你粘贴的内容将以格式化形式显示在 **可视化编辑器** 中，而在 **代码编辑器** 中，你将能够看到 Overleaf 为你生成的 LaTeX 代码。（不过不要尝试把带格式文本粘贴到 **代码编辑器** 那里！）

你可以粘贴到 **可视化编辑器** 来自各种来源的内容，包括 Google 文档、 [Microsoft 365](https://www.microsoft.com/en-us/microsoft-365) （以前称为 Microsoft Office）、 [LibreOffice](https://www.libreoffice.org/)以及网站。目前不支持从 PDF 文档中粘贴带格式内容。为了在使用 Microsoft 的工具时获得最佳效果，请使用在线版本，不过桌面应用程序也受支持。

在将带格式内容粘贴到 **可视化编辑器**后，你会看到一个下拉菜单，让你可以把粘贴的（带格式的）内容改回纯文本（不带格式）：

![图示：将带格式文本粘贴到 Overleaf 时显示的菜单](/files/2498350a347c0d5f78ebee90f101c4c2db1154c9)

* **不带格式粘贴** 可将带格式文本转换为纯文本。
* **带格式粘贴** 会切换回带格式文本。

## 粘贴纯文本

你可以粘贴 *无格式纯文本* 到 **可视化编辑器** 或 **代码编辑器** ，方法如下：

* Windows/Linux：Ctrl+Shift+V
* MacOS：Cmd+Shift+V

## 所需的 LaTeX 宏包

要支持将图片和其他内容粘贴到 Overleaf，你需要将以下宏包添加到你的 [LaTeX 文档导言区](/latex/zh-cn/latex-ji-chu/01-learn-latex-in-30-minutes.md#the-preamble-of-a-document):

* [`hyperref`](https://ctan.org/pkg/hyperref?lang=en)：用于支持 [超链接](/latex/zh-cn/wen-dang-jie-gou/09-hyperlinks.md) ，这些链接包含在粘贴的内容中。
* [`graphicx`](https://ctan.org/pkg/graphicx)：提供了 [`\includegraphics` 命令](/latex/zh-cn/latex-ji-chu/01-learn-latex-in-30-minutes.md#adding-images) 在项目中使用粘贴图形所需的命令。

## 将表格粘贴到你的 Overleaf 项目中

**可视化编辑器** 无法完全保留粘贴到你项目中的每个表格的形式和样式，但你仍然可以通过粘贴在其他应用程序中创建的各种表格来节省时间和精力。

**可视化编辑器** 会尝试保留并预览以下表格元素：

* 横向合并的单元格（跨越多列）
* 应用于单元格的边框
* 表格单元格内文本的格式
* 表格标题和表头

**可视化编辑器** 还可以让你 [修改粘贴的表格](/latex/zh-cn/zhi-shi-ku/067-how-to-generate-and-insert-latex-tables-in-overleaf.md#editable)，例如编辑单元格内容或添加行和列。你还可以切换到 **代码编辑器** 以进行更改，包括设置控制表格 [在排版文档中的位置的 LaTeX 参数](https://learn.overleaf.com/learn/Inserting_Images#Positioning).

### 粘贴表格示例

下面的视频演示了从维基百科粘贴表格——请注意超链接和文本样式是如何保留的。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/2ENPw4QceCpzglQafnkFWU/f7be441c53822a37aa9d9d192fd43410/PastedTable.mp4>" %}

## 将图片粘贴到你的 Overleaf 项目中

你可以将单张图片粘贴到 **可视化编辑器** 和 **代码编辑器** （但仅 **可视化编辑器** 提供图片预览）。 [粘贴多张图片](#can-i-paste-multiple-images) 目前不受支持。

![图示：从计算机上传的模态窗口](/files/c4679533d10bf031eb9353ff5c27aaa707e63d05)

你可以：

* 为用于保存粘贴图片的文件命名。
* 选择保存它的项目文件夹。
* 决定是否使用图注。
* 决定是否包含标签（用于引用表格）。
* 设置图片宽度（作为 `\linewidth`).

你粘贴的任何图片都将以 .png 文件的形式保存在你的 Overleaf 项目中。然后它会通过自动生成的 LaTeX 代码被纳入你的文档。 **可视化编辑器** 会提供粘贴图片的预览，但 **代码编辑器** 只会显示 LaTeX 代码。

### 粘贴图片示例

图片可以从许多来源复制，包括网页，但此视频片段演示了从 [gimp](https://www.gimp.org/) 复制图片并将其粘贴到 **可视化编辑器**中。请注意使用 **代码编辑器** 来设置自定义图片宽度为 `0.85\linewidth`.

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/3v01l6iGqXyAD4zaSosGbN/be53d9dad5fa4cb95b8177ec69c01cf3/PastingAnImage.mp4>" %}

视频演示中使用的图片是从一篇 [关于人口密度的维基百科条目](https://en.wikipedia.org/wiki/World_population#/media/File:Population_Density,_v4.11,_2020_\(48009093621\).jpg).

## 将带样式文本粘贴到你的 Overleaf 项目中

为了保留下列项目的格式，请将它们粘贴到 Overleaf 的 **可视化编辑器** 中，使用 Ctrl+V（在 Windows/Linux 上）或 Cmd+V（在 MacOS 上）：

* 标题
* **粗体文本**
* *斜体文本*
* [超链接](http://www.google.com)
* 代码块（例如包裹在 `HTML 中的标签）`
* `符号，例如 &, %, …, $50.00`

`粘贴带格式文本示例下一个视频片段演示了从 Google 文档复制的带格式文本的粘贴。将列表粘贴到你的 Overleaf 项目中项目符号和编号列表可以粘贴到 Overleaf 的`` `**`可视化编辑器`**` ``中，使用 Ctrl+V（在 Windows/Linux 上）或 Cmd+V（在 MacOS 上）进行粘贴。粘贴列表示例下一个视频片段演示了从浏览器页面和 LibreWriter 文档中复制的多级项目符号和编号列表的粘贴。请注意粗体和斜体文本也会被保留。描述列表可视化编辑器也支持创建和编辑描述列表。关于粘贴带格式内容的常见问题可以使用拖放吗？`**`可视化编辑器`**` ``支持使用拖放上传 .png、.jpg 或 .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/zh-cn/zhi-shi-ku/075-how-to-paste-formatted-content-into-overleaf.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.
