> 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/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` 命令。你会注意到图像现在已经移到了另一页。我们可以通过在 `\begin{figure}` 命令后面的方括号中添加一个说明符来影响 LaTeX 放置图形的位置。你可能想了解六种说明符。第一个是小写的 `h` ，表示“here”，并将图形大致放在代码在文本中出现的位置。你也可以使用小写的 `t` ，它会把图形放在页面顶部，小写的 `b` ，它会把图形放在底部，以及小写的 `页` ，它会把图形放在专门用于图形和其他浮动体的单独页面上。感叹号也是一个有效的说明符，它会覆盖 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://overleaf-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.
