LaTeX Error: Can be used only in preamble

This error appears when you have included a package or class in the main body of your document, instead of in the preamble. The preamble to the document consists of everything written before \begin . In the preamble you define the type of document you are writing, the language and several other elements. For instance, a normal document preamble would look like this:

\documentclass[12pt, letterpaper]article> \usepackage[utf8]inputenc> \usepackageamsmath> \titleFirst document> \authorHubert Farnsworth \thanksfunded by the ShareLaTeX team>> \dateFebruary 2014> 

If you write \usepackage in the main body of the document (after \begin ) instead of in the preamble, you will generate the error message shown below.

LaTeX Error: Can be used only in preamble.

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. . l.4 \usepackage Your command was ignored. Type I to replace it with another command, or to continue without it. [1

To fix this error, make sure that all \usepackage commands, as well as \documentclass[. ] , are written before \begin . To learn more about how to structure a document in L a T e X , check out our documentation.

Overleaf guides

LaTeX Basics

Mathematics

Figures and tables

References and Citations

Languages

Document structure

Formatting

Fonts

Presentations

Commands

Field specific

Class files

Advanced TeX/LaTeX