LaTeX Error: Can be used only in preamble — Preamble command in the document body
A command such as \usepackage is used after \begin{document}.
Fix
Move it above \begin{document}.
Example
Reproduced on TeX Live 2026 by CI · pdflatex · corpus/usepackage-after-begin-document
\usepackage after \begin{document}
main.tex\documentclass{article}
\begin{document}
\usepackage{booktabs}
\begin{tabular}{ll}\toprule
A & B \\ \bottomrule
\end{tabular}
\end{document}\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{ll}\toprule
A & B \\ \bottomrule
\end{tabular}
\end{document}main.log! LaTeX Error: Can be used only in preamble.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.3 \usepackage
{booktabs}
Your command was ignored.
Type I <command> <return> to replace it with another command,
or <return> to continue without it.
…