> 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/ja/latexer/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}`**。LaTeX で文書を構成する方法について詳しくは、私たちの [ドキュメント](/latex/ja/latexno/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/ja/latexer/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.
