> 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/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 代码， [插入一幅图像并将其放置在 figure 环境中](/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 项目中的图形文件创建图形。如下方动画截图所示，你先选择一个项目，然后选择一个先前 *上传* 到该项目中的文件，或者一个文件 *输出* （生成）的文件——例如，由以下内容生成的 PDF 图形： [外部化 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)。请参见章节 [从输出文件中选择](#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://ayakaleaf-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.
