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

# Lỗi LaTeX: Chỉ có thể được dùng trong phần tiền đề

Lỗi này xuất hiện khi bạn đã đưa một gói hoặc lớp vào phần thân chính của tài liệu, thay vì trong phần tiền tố. Phần tiền tố của tài liệu bao gồm mọi thứ được viết trước **`\begin{document}`**. Trong phần tiền tố, bạn xác định loại tài liệu đang viết, ngôn ngữ và một số yếu tố khác. Ví dụ, một phần tiền tố tài liệu thông thường sẽ trông như sau:

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

\title{Tài liệu đầu tiên}
\author{Hubert Farnsworth \thanks{được tài trợ bởi nhóm ShareLaTeX}}
\date{Tháng 2 năm 2014}
```

Nếu bạn viết **`\usepackage{...}`** trong phần thân chính của tài liệu (sau **`\begin{document}`**) thay vì trong phần tiền tố, bạn sẽ tạo ra thông báo lỗi hiển thị bên dưới.

main.tex, dòng 7

Lỗi LaTeX: Chỉ có thể được dùng trong phần tiền tố.

Hãy xem tài liệu hướng dẫn LaTeX hoặc LaTeX Companion để biết giải thích. Gõ H để được trợ giúp ngay lập tức. ... l.4 \usepackage {amsmath} Lệnh của bạn đã bị bỏ qua. Gõ I để thay thế nó bằng một lệnh khác, hoặc tiếp tục mà không có nó. \[1

Để khắc phục lỗi này, hãy đảm bảo rằng tất cả **`\usepackage{...}`** các lệnh, cũng như **`\documentclass[...]{...}`**, được viết trước **`\begin{document}`**. Để tìm hiểu thêm về cách cấu trúc một tài liệu trong LaTeX, hãy xem [tài liệu](/latex/vi/kien-thuc-co-ban-ve-latex/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/vi/loi-latex/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.
