> 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/geng-duo-zhu-ti/34-latex-video-tutorial-for-beginners-video-4.md).

# LaTeX 新手视频教程（视频 4）

[视频 1](/latex/zh-cn/geng-duo-zhu-ti/31-latex-video-tutorial-for-beginners-video-1.md) | [视频 2](/latex/zh-cn/geng-duo-zhu-ti/32-latex-video-tutorial-for-beginners-video-2.md) | [视频 3](/latex/zh-cn/geng-duo-zhu-ti/33-latex-video-tutorial-for-beginners-video-3.md) | 视频 4 | [视频 5](/latex/zh-cn/geng-duo-zhu-ti/35-latex-video-tutorial-for-beginners-video-5.md) | [视频 6](/latex/zh-cn/geng-duo-zhu-ti/36-latex-video-tutorial-for-beginners-video-6.md) | 视频 7

这套分为七部分的 LaTeX 教程视频最初发布于 2013 年；因此，由于 ShareLaTeX 的发展以及后来 ShareLaTeX 与 Overleaf 的合并，如今的编辑器界面已经发生了很大变化。不过，视频内容仍然具有相关性，并会教你 LaTeX 的基础知识——这些技能和经验适用于所有平台。你不需要任何先前的背景知识，在这些 LaTeX 指南结束时，你将能够创建和编写基本的 LaTeX 文档，并具备开始学习如何创建更复杂文档的知识。每个视频都附有一份文字稿（列在视频下方）——这些就地文字稿取代了每个教程开头显示的 URL。

### LaTeX 中的图像

**注意：** 你可以通过以下方式打开视频中使用的项目： [点击此链接](https://www.sharelatex.com/project/51ee458d335f3d6370c9c58a).

{% embed url="<https://www.youtube.com/embed/21Y8LnKjfKE>" %}

### 视频文字稿

在 [上一个视频](/latex/zh-cn/geng-duo-zhu-ti/33-latex-video-tutorial-for-beginners-video-3.md) 我们已经看过如何在我们的 LaTeX 文档中使用基础数学和公式。在这个视频中，我们将看看如何向文档中插入图形。在开始在 LaTeX 中使用图像之前，我们需要加载 `graphicx` 宏包。为此我们使用 `\usepackage` 在导言区使用该命令，并输入 `graphicx`，拼写时在 c 后面用 x 而不是 s，放入花括号中，如下所示： `\usepackage{graphicx}`.

接下来我们需要将想要使用的图像上传到 ShareLaTeX 项目中。为此，请点击左侧面板中的‘new’按钮并选择‘upload file’。上传完成后，图像会出现在项目面板中，现在就可以使用了。我上传了一张名为‘lion’的图像，它是一个 PNG 文件。你也可以使用 JPG 文件或 PDF 文件。

要将图像放入文档中，我们使用 `\includegraphics` 命令。然后在花括号中输入想要使用的图像文件名，但不包含扩展名。如果我现在编译文档，我的图片就会出现在页面上。我们可以在命令后立即、但在文件名前使用方括号，向 LaTeX 提供更多关于我们希望图像外观的指令。我们可以使用 scale 一词，后接等号和一个数字来缩放图像的大小。例如，输入 `scale=2` 我们将图像大小加倍。我们也可以通过设置高度和/或宽度来更改大小。这样做时，我们必须告诉 LaTeX 想要修改哪一个，然后给它一个以厘米为单位的数值。如果我们只更改其中一个，LaTeX 会保持图像的纵横比。若要同时修改两者，我们只需在第一个参数后加一个逗号和一个空格，然后再添加第二个参数。我们还可以通过使用关键字 `angle` 后跟等号和你想要将其逆时针旋转的度数。

尽管这种插入图形的方法很有用，但我们通常希望对图像的位置有更多控制。我们也可能希望添加标题并对其进行引用。要实现这些功能，我们需要使用 figure 环境。与所有环境一样，我们需要使用一个 `\begin` 和 `\end` 命令将其包裹起来。所以让我们添加一个 `\begin{figure}` 和 `\end{figure}` 命令，放在我们现有的两侧 `\includegraphics` 命令。你会注意到图像现在已经移到了另一页。我们可以通过在该命令后面的方括号中添加一个定位参数来影响 LaTeX 放置该图形的位置。 `\begin{figure}` 命令。这里有六种你可能需要了解的定位参数。第一种是一个小写的 `h` ，表示“here”，它会将图形大致放在代码在文本中出现的位置。你也可以使用一个小写的 `t` ，它会将其放在页面顶部，一个小写的 `b` ，它会将其放在底部，以及一个小写的 `p` ，它会将其放在专门用于图形和其他浮动体的单独页面上。感叹号也是一种有效的参数，它会覆盖 LaTeX 对图形适合放置位置的判断。最后还有一个特殊标识符，一个大写的 `H` ，它会将图形精确放在你在 LaTeX 代码中所在的位置，不过你需要使用 `float` 宏包才能使其生效。你通常需要将感叹号与某个小写字母参数一起使用，才能把图形放到你想要的位置。你可能还想使用 `\centering` 命令使图形居中。

你可以通过使用 `\caption` 命令为图形添加标题。如果你想让标题出现在图片上方，就把该命令添加到代码中位于 `\includegraphics` 命令上方；否则将其放在下方。

最后让我们简要提一下标签和引用。在 LaTeX 中，我们可以给编号项目（例如图形）添加标签。这使我们能够在文档的其他地方引用一个已标记的项目。要为项目添加标签，请使用 \label 命令，然后选择一个名称。例如，我可以把这个图形标记为 `fig:lion`。然后如果我放入一个 `\ref` 命令并配合我选择的名称，它就会输出分配给该图形的编号。或者，我也可以使用 `\pageref` 命令来输出我的图形所在的页码。这非常有用，因为这意味着如果我之后在这张图之前又插入一些图形，LaTeX 仍会给我正确更新后的编号。

这就结束了我们关于在 LaTeX 中使用图像的讨论。在 [下一个视频](/latex/zh-cn/geng-duo-zhu-ti/35-latex-video-tutorial-for-beginners-video-5.md) 中，我们将看看如何使用 BibTeX。

[视频 1](/latex/zh-cn/geng-duo-zhu-ti/31-latex-video-tutorial-for-beginners-video-1.md) | [视频 2](/latex/zh-cn/geng-duo-zhu-ti/32-latex-video-tutorial-for-beginners-video-2.md) | [视频 3](/latex/zh-cn/geng-duo-zhu-ti/33-latex-video-tutorial-for-beginners-video-3.md) | 视频 4 | [视频 5](/latex/zh-cn/geng-duo-zhu-ti/35-latex-video-tutorial-for-beginners-video-5.md) | [视频 6](/latex/zh-cn/geng-duo-zhu-ti/36-latex-video-tutorial-for-beginners-video-6.md) | 视频 7


---

# 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/geng-duo-zhu-ti/34-latex-video-tutorial-for-beginners-video-4.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.
