> 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/13-latex-error-can-be-used-only-in-preamble.md).

# LaTeX 錯誤：只能在前言中使用

當你把套件或類別包含在文件的主體中，而不是放在前言區時，就會出現這個錯誤。文件的前言區包含在之前寫下的所有內容 **`\begin{document}`**。在前言區中，你定義正在撰寫的文件類型、語言以及其他幾個元素。例如，一個正常的文件前言區會像這樣：

```latex
\documentclass[12pt, letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}

\title{First document}
\author{Hubert Farnsworth \thanks{funded by the ShareLaTeX team}}
\date{February 2014}
```

如果你寫入 **`\usepackage{...}`** 在文件的主體中（在 **`\begin{document}`**）之後，而不是放在前言區，你就會產生如下所示的錯誤訊息。

main.tex，第 7 行

LaTeX 錯誤：只能在前言區中使用。

請參閱 LaTeX 手冊或 LaTeX Companion 以了解說明。輸入 H 取得即時說明。... l.4 \usepackage {amsmath} 你的命令已被忽略。輸入 I 以將其替換為另一個命令，或在不使用它的情況下繼續。\[1

要修正這個錯誤，請確認所有 **`\usepackage{...}`** 命令，以及 **`\documentclass[...]{...}`**，都寫在 **`\begin{document}`**&#x4E4B;前。若要進一步了解如何在 LaTeX 中結構化文件，請查看我們的 [說明文件](/latex/zh-tw/latex-ji-chu/01-learn-latex-in-30-minutes.md).


---

# 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/13-latex-error-can-be-used-only-in-preamble.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.
