> 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/068-how-to-insert-figures-in-overleaf.md).

# 如何在 Overleaf 中插入图表

Overleaf 提供 3 种创建 LaTeX 图形的方法：

1. 使用 [**插入图形** 按钮](#using-insert-figure-to-add-a-figure-to-your-project) (![The Insert Figure button on the editor toolbar](/files/fadba5f0c0afa0cc0db889566e193b156d7724cf)）以将图形插入到 **可视化编辑器** 或 **代码编辑器**.
2. [复制并粘贴图像](/latex/zh-cn/zhi-shi-ku/075-how-to-paste-formatted-content-into-overleaf.md#pasting-images-into-your-overleaf-project) 到 **可视化编辑器** 或 **代码编辑器**.
3. 使用 **代码编辑器** 以编写 LaTeX 代码， [插入图形并将其放入图形环境中](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md).

选项 1 和 2 会自动生成创建图形所需的 LaTeX 代码，但如果你是有经验的 LaTeX 用户，你可能更喜欢选项 3，因为它提供了最大的灵活性。如果你是 LaTeX 新手，那么选项 1， **插入图形** 按钮（本页重点介绍的内容），是一个很好的入门方式。

在使用这些图形创建方法之前，请确保你的主 LaTeX 文件已经通过编写 `graphicx` 宏包 `\usepackage{graphicx}` 在其 [导言区](/latex/zh-cn/latex-ji-chu/01-learn-latex-in-30-minutes.md#the-preamble-of-a-document).

## 使用可视化编辑器和代码编辑器

在解释如何插入图形之前，值得注意 **可视化编辑器**的图形预览功能。

图形可以插入到 **可视化编辑器** 或 **代码编辑器**中，但只有 **可视化编辑器** 提供图形预览，并带有一个按钮，可打开一个模态窗口让你进行更改。下面的简短视频片段演示了 **可视化编辑器**的图形预览功能。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/4ohFnejYVn89OUj2fAbJ6F/18ad3cd10b0b3ceb7955cc651c92eedb/VisualEditorDemo.mp4>" %}

## 使用“插入图形”将图形添加到你的项目中

使用以下步骤将图形插入到 Overleaf LaTeX 文档中。

1. 选择你想使用的编辑器： **可视化编辑器** 或 **代码编辑器**.
2. 选择 **插入图形** 按钮（![The Insert Figure button on the editor toolbar](/files/fadba5f0c0afa0cc0db889566e193b156d7724cf)）以显示用于插入图形的选项列表：

   ![插入图形的选项列表](/files/105dff096eda0513952b072cc2be7a91022e435a)
3. 使用以下文档链接跳转到你感兴趣的选项：

* [从计算机上传](#upload-from-computer)
* [来自项目文件](#from-project-files)
* [来自另一个项目（视频演示）](#from-another-project)
* [来自 URL（视频演示）](#from-url)

### 从计算机上传

此选项使用从你的设备上传的图形文件创建图形。

![上传文件时显示的“从计算机上传”模态窗口](/files/fc8cbe40655a3a69684b31ff3a77d56c4ff1406d)

要使用此选项：

1. 使用以下方法之一上传图形：

* 将图形文件拖放到模态窗口中（在所示区域内）
* 将图像粘贴到模态窗口中（在所示区域内）
* 手动选择设备上的文件

3. 为图形文件命名。
4. （可选）选择一个项目文件夹来保存该文件。
5. 决定是否使用图注。
6. 决定是否包含标签（用于 [引用图形](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md#labels-and-cross-references)).
7. 设置图像宽度（作为……的比例 `\linewidth`).
8. 选择 **插入图形** 以上传图形并根据你的选择自动生成一个 LaTeX `figure` 环境。

### 来自项目文件

此选项使用之前上传到你当前项目中的某个图形文件来创建图形。

![用于选择项目文件以创建图形的“从项目文件插入”模态窗口](/files/3892c3639874548404d8e8b02039474aa93e4609)

要使用此选项：

1. 选择你项目中的一个图形。
2. 决定是否使用图注。
3. 决定是否包含标签（用于 [引用图形](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md#labels-and-cross-references)).
4. 设置图像宽度（作为……的比例 `\linewidth`).
5. 选择 **插入图形** 以自动生成一个 LaTeX `figure` 环境。

### 来自另一个项目

此选项让你可以使用其他 Overleaf 项目中的图形文件来创建图形。如下方动画截图所示，你先选择一个项目，然后选择之前 *上传* 到该项目的文件，或者该项目 *输出* 生成的文件——例如，由 [外部化 TikZ 图形](https://learn.overleaf.com/learn/Questions/I_have_a_lot_of_tikz,_matlab2tikz_or_pgfplots_figures,_so_I%27m_getting_a_compilation_timeout._Can_I_externalise_my_figures%3F#How_to_externalize_TikZ_graphics)生成的 PDF 图形。请参见章节 [从输出文件中选择](#select-from-output-files) ，查看如何使用另一个项目创建的输出文件的视频片段。

![一个动画 GIF，展示如何选择由另一个项目生成的文件](/files/063717cdf01ad98d5aa990b7627cc6a2ee8f59b4)

要使用此选项：

1. 选择一个包含你想在当前项目中使用的图形文件的项目。
2. 选择该项目中的一个图形：
   * 一个 **图像文件** *上传到* 该项目，或者
   * 一个 [**输出文件**](#select-from-output-files) *由* 该项目生成。
3. 为图形文件命名。
4. （可选）选择一个项目文件夹来保存该文件。
5. 决定是否使用图注。
6. 决定是否包含标签（用于 [引用图形](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md#labels-and-cross-references)).
7. 设置图像宽度（作为……的比例 `\linewidth`).
8. 选择 **插入图形** 以自动生成一个 LaTeX `figure` 环境。

#### 从输出文件中选择

下面的视频片段将带你了解如何将一个由其他项目生成的文件整合到你的当前项目中，该项目生成 [外部化的 TikZ 图形](/latex/zh-cn/wen-da/60-i-have-a-lot-of-tikz-matlab2tikz-or-pgfplots-figures-so-i-m-getting-a-compilation-timeout.-can-i.md#how-to-externalize-tikz-graphics).

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/1hcdCRW7PFioG58vexEMpf/60b86288419fea290ad4b43a633afda3/FigureFromExternalProjectFile.mp4>" %}

### 来自 URL

此选项让你可以使用通过 URL 添加（下载）到你项目中的图形来创建图形。

![一个显示通过 URL 下载文件的模态窗口的图像](/files/dfd9351d1f46b9058acb7c985d0e7d4c65e441ae)

要使用此选项：

1. 粘贴一个 [直接下载链接](https://en.wikipedia.org/wiki/Direct_download_link) （URL）到 **图片 URL** 字段中。
2. 为图形文件命名。
3. （可选）选择一个项目文件夹来保存它。
4. 决定是否包含图形标题。
5. 决定是否包含标签（用于 [引用图形](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md#labels-and-cross-references)).
6. 设置图像宽度（作为……的比例 `\linewidth`).
7. 选择 **插入图形** 以自动生成一个 LaTeX `figure` 环境。

下面的视频片段演示了如何使用一个 [Google Drive 下载 URL](/latex/zh-cn/zhi-shi-ku/051-how-can-i-upload-files-from-google-drive.md)。它还展示了如何更改图形大小并为其添加标题。

{% embed url="<https://videos.ctfassets.net/nrgyaltdicpt/29hcjGmsEQewhuCVQaWkSr/2cef229050a36a87b86dc0aabdde2858/InsertFigureURL.mp4>" %}


---

# 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/068-how-to-insert-figures-in-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.
