> 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-tw/latex-cuo-wu/16-latex-error-missing-begin-document.md).

# LaTeX 錯誤：缺少 \begin document

當你忘記包含時，就會出現此錯誤 **`\begin{document}`** 在你的文件中。若你未撰寫，也可能會出現 **`\documentclass[...]{...}`** 於你的主要文件開頭。

## 常見原因

**忘記包含 \begin{document}：**

此錯誤最基本的原因是你忘了撰寫 **`\begin{document}`** 在主要文件的前言之後。如果你犯了這個錯誤，將會產生如下所示的錯誤訊息：

main.tex，第 5 行

LaTeX 錯誤：缺少 \begin{document}。

請參閱 LaTeX 手冊或《LaTeX Companion》以獲得說明。輸入 H 可立即取得協助。... 你現在遇到麻煩了。請嘗試輸入以繼續。若無法運作，請輸入 X 離開。

要解決此錯誤，只需確認你已包含 **`\begin{document}`** 在主要文件的前言之後。請參閱 [這裡](/latex/zh-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md) 以進一步了解如何在 LaTeX 中組織文件。

**\documentclass\[...]{...} 放在錯誤的位置：**

此錯誤的另一個常見原因是如果 **`\documentclass[...]{...}`** 被寫在錯誤的位置。這必須寫在主要文件的開頭。如果你的前言有單獨的檔案，你 **不能** 包含 **`\documentclass[...]{...}`** 在那個檔案中包含它。它仍然必須出現在主要專案檔案的頂端，否則只會編譯前言檔。

**主要文件設定不正確：**

如果你在左側選單中將主要文件設定錯誤，也可能會出現此錯誤。這種情況可能發生於 **`\documentclass[...]{...}`** 被寫在錯誤的位置，因此如有需要，你應先更正這一點。若要變更主要文件的選擇，請開啟左側選單：

![Lefthandmenu.PNG](/files/5a5a818ebbfe23e845db47fcaa03d2e4f5a3e7df)

然後前往 *主要文件* 下拉式選單：

![Maindocument.PNG](/files/353c7dc83110650f20853205a530151f01e139fd)


---

# 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-tw/latex-cuo-wu/16-latex-error-missing-begin-document.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.
