LaTeX Cheatsheet - LaTeX Academic Typesetting Reference

Opening a .tex file two hours before the deadline rarely breaks on the math; it breaks on a figure that floated away, a bibliography key that no longer matches, or an image path that dies on another machine. This table is grouped by document structure, text formatting, math, lists, tables, figures, and bibliography, with each entry giving both the syntax and the macro package it needs, so a compilable skeleton exists before you type a paragraph of prose. The working rule is unglamorous but reliable: get one clean pdflatex pass first, then add content one block at a time, one package at a time, and roll back to the last passing state the moment something breaks, so the failing line is always known. Reach for it when switching templates, tuning equation spacing, converting a long table to booktabs style, renaming citation keys in bulk, or chasing undefined citation errors. The line against Markdown is that LaTeX is a typesetting system: it owns float placement, equation numbering, and multi-level tables of contents.

Reference·45 commands·Last updated 2026-07-21
latexTypesettingAcademic

Typical Use Case

For authors producing papers, technical reports or any document heavy on formulas, especially where cross-references, figures and bibliographies are involved. The sheet connects three layers: document structure (classes, packages, title, table of contents), content (inline versus numbered equations, alignment environments, and float parameters that keep figures from drifting), and citations, where label and ref replace hand-numbered references that break after one revision. Pitfalls cover spacing that dies in math mode and floats landing in the wrong place.

Document Structure 8

\documentclass{article}
Pick the document class (article / report / book / beamer)
\usepackage[utf8]{inputenc}
Set the input character encoding
\usepackage{amsmath}
Math package: aligned equations, double-struck symbols, and more
\title{Title} \author{Author} \date{\today}
Title, author and date metadata
\begin{document} ... \end{document}
The document environment; all body content lives inside it
\maketitle
Typeset the title block
\tableofcontents
Generate the table of contents
\section{} \subsection{} \subsubsection{}
Sectioning commands for the document outline

Text Formats 8

\textbf{bold}
Bold text
\textit{italic}
Italic text
\underline{underline}
Underlined text
\emph{emphasis}
Emphasis (usually rendered italic)
\texttt{monospace}
Monospace typewriter font
\footnote{footnote text}
Footnote
\label{sec:intro} \ref{sec:intro}
Cross-reference: label a target then refer to it
\cite{key}
Cite a bibliography entry

Math Formulas 10

$E = mc^2$
Inline math formula
\[ E = mc^2 \]
Displayed math formula (unnumbered)
\begin{equation} ... \end{equation}
Numbered equation environment
\begin{align} ... \end{align}
Align multiple equations line by line
\frac{a}{b}
Fraction
\sqrt{x}
Square root
\sum_{i=1}^{n} x_i
sum
\int_{a}^{b} f(x) dx
Definite integral
\alpha \beta \gamma \delta
Greek letters
\infty \partial \nabla
Special symbols: infinity, partial derivative, gradient

List Environments 3

\begin{itemize} \item ... \end{itemize}
Unordered (bulleted) list
\begin{enumerate} \item ... \end{enumerate}
Ordered (numbered) list
\begin{description} \item[term] desc \end{description}
Description list of terms and their definitions

Tables 6

\begin{tabular}{|c|c|c|} ... \end{tabular}
Table environment with a column spec
\hline
Horizontal rule between rows
a & b & c \\
Separate cells with & and end the row with \
\multicolumn{2}{|c|}{text}
Merge a cell across several columns
\begin{table}[htbp] ... \end{table}
Float a table so LaTeX can choose its position
\caption{Caption} \label{tab:1}
Table caption plus label for cross-references

Charts 5

\usepackage{graphicx}
Graphics package for including images
\includegraphics[width=0.5\textwidth]{image.png}
Insert an image scaled to a fraction of the text width
\begin{figure}[htbp] ... \end{figure}
Float a figure so LaTeX can choose its position
\caption{Caption} \label{fig:1}
Figure caption plus label for cross-references
\begin{subfigure} ... \end{subfigure}
Sub-figure (requires the subcaption package)

References 5

\bibliographystyle{plain}
Bibliography entry style (plain, unsrt, abbrv ...)
\bibliography{references}
Read bibliography entries from a .bib file
\begin{thebibliography}{99} ... \end{thebibliography}
Hand-written bibliography environment
\cite{key}
Cite an entry
\citep{key} \citet{key}
Parenthetical / textual citation (natbib)

Parameter matrix

ParameterEffectExample
\documentclass{article}Choose the document class (article/report/book/beamer)\documentclass{article}
\usepackage[utf8]{inputenc}Set the input encoding\usepackage[utf8]{inputenc}
\usepackage{amsmath}Load the math package; environments like align/equation depend on it\usepackage{amsmath}
\usepackage{graphicx}Load the graphics package; \includegraphics depends on it\usepackage{graphicx}
\title{} \author{} \date{}Declare the title, author and date\title{Title} \author{Author} \date{\today}
\maketitleGenerate the title page\maketitle
\tableofcontentsGenerate the table of contents\tableofcontents
\section{} \subsection{} \subsubsection{}Section-level commands\section{} \subsection{}
\begin{document} ... \end{document}Document body environment; all content must go inside it\begin{document} ... \end{document}
\textbf{} / \textit{} / \emph{} / \underline{}Bold, italic, emphasis, underline\textbf{bold}
\texttt{}Typeset code in a monospace font\texttt{monospace}
\footnote{}Insert a footnote\footnote{footnote text}
\label{} + \ref{}Label and cross-reference to avoid hard-coded numbers\label{sec:intro} \ref{sec:intro}
$ ... $Inline math environment$E = mc^2$
\[ ... \]Display math without numbering\[ E = mc^2 \]
\begin{equation} ... \end{equation}Numbered display equation that can be referenced by \ref\begin{equation} ... \end{equation}
\begin{align} ... \end{align}Multi-line aligned equations, aligned on &, broken with \\\begin{align} ... \end{align}
\frac{a}{b}Fraction\frac{a}{b}
\sqrt{x}Square root\sqrt{x}
\sum_{i=1}^{n} x_iSummation with limits\sum_{i=1}^{n} x_i
\int_{a}^{b} f(x) dxIntegral with limits\int_{a}^{b} f(x) dx
\alpha \beta \gamma \deltaGreek letter commands\alpha \beta \gamma \delta
\infty \partial \nablaInfinity, partial derivative and gradient symbols\infty \partial \nabla
\left( ... \right)Let brackets resize automatically with the content\left( \frac{a}{b} \right)
itemize / enumerate / descriptionThe three list environments: unordered, ordered and description\begin{itemize} \item ... \end{itemize}
\begin{tabular}{|c|c|c|} ... \end{tabular}Table environment; vertical bars and c set the column alignment\begin{tabular}{|c|c|c|} ... \end{tabular}
\hlineHorizontal rule in a table\hline
\multicolumn{2}{|c|}{text}A cell spanning multiple columns\multicolumn{2}{|c|}{text}
\begin{table}[htbp] ... \end{table}Floating table; htbp controls the placement preference\begin{table}[htbp] ... \end{table}
\caption{} + \label{}Figure/table caption and label; numbering is maintained automatically\caption{Caption} \label{tab:1}
\includegraphics[width=...]{file}Insert an image scaled proportionally\includegraphics[width=0.5\textwidth]{image.png}
\begin{figure}[htbp] ... \end{figure}Floating figure environment\begin{figure}[htbp] ... \end{figure}
\begin{subfigure} ... \end{subfigure}subfigure environment, requires the subcaption package\begin{subfigure} ... \end{subfigure}
\bibliographystyle{plain}Specify the bibliography style\bibliographystyle{plain}
\bibliography{references}Load a bib file to generate the bibliography\bibliography{references}
\begin{thebibliography}{99}Hand-write the bibliography list when not using a bib file\begin{thebibliography}{99} ... \end{thebibliography}
\cite{} / \citep{} / \citet{}Plain, parenthetical and textual citations (natbib)\cite{key}

Common pitfalls

SymptomSpaces in math formulas vanish completely, and terms end up jammed together.

CauseMath mode ignores ordinary spaces, so spaces in the source produce no typesetting width.

FixUse \left( and \right) so brackets scale automatically with the content, and rely on the alignment environment ampersand and typesetting rules for spacing between terms instead of typing spaces.

SymptomA figure ended up on a completely unexpected page, even after the references.

CauseLaTeX floats only treat [htbp] as a placement preference; the final position is decided by the typesetting algorithm, and the float is moved as an unbreakable whole.

FixChange [htbp] to [H] (requires the float package) to force in-place placement, or move the float closer to where it is first referenced by \ref to reduce drift.

SymptomAfter the first compile all \ref show ?? and the cross-references and table of contents are wrong.

CauseCross-references need one compile to write labels into the auxiliary file and a second compile to fill in the numbers.

FixCompile twice in a row (or clean the auxiliary files and compile twice), confirm the aux file is generated, then double-check the numbers.

SymptomSymbols like underscores, percent signs and hash marks in body text are mis-typeset or even trigger undefined command errors.

CauseThese characters have special meaning in LaTeX and were not escaped with the corresponding commands.

FixUse \underline{} or the escaped form in text environments for underscores in body text, write percent as \% and hash as \#, rather than typing the raw characters.

Symptom? or boxes appear in the document, and all Chinese text is missing from the PDF.

CauseThe engine is not handling UTF-8 Chinese correctly, or the Chinese typesetting support configuration is missing.

FixMake sure the file is saved as UTF-8 and keep \usepackage[utf8]{inputenc} in the preamble, then add the matching Chinese support package for the engine you use.

SymptomAfter reordering sections, figure numbering and in-text references no longer match.

CauseNumbers were hard-coded into the body instead of being maintained automatically with \label + \ref.

FixConvert everything to \label{tab:1} + \ref{tab:1} so numbers re-flow automatically with the document structure; always generate caption text with \caption{} too.

SymptomThe subfigure environment errors out: an environment definition such as subfigure cannot be found.

Causesubfigure depends on the subcaption package, which was not loaded in the preamble.

FixLoad the subcaption package in the preamble before using \begin{subfigure} ... \end{subfigure}.

Troubleshooting

  1. 1Compile twice in a row so cross-references and the table of contents settle

    pdflatex main.tex && pdflatex main.tex

    After the second compile, the numbers for \ref and \tableofcontents should all be resolved.

  2. 2Clean auxiliary files and rebuild to rule out interference from stale ones

    latexmk -C && latexmk main.tex

    latexmk decides how many passes are needed automatically; the output should include records of the aux file being regenerated.

  3. 3Inspect the full build log to locate the error line

    pdflatex main.tex > build.log 2>&1

    Search build.log for Undefined control sequence or LaTeX Error to pin down the exact line number.

  4. 4Confirm the image is actually referenced and its size resolves

    \includegraphics[width=0.5\textwidth]{image.png}

    If it reports the file not found, check whether the path and extension match the actual file on disk.

  5. 5Check that the bibliography is generated correctly

    \bibliographystyle{plain} + \bibliography{references}

    Confirm every entry in references.bib has a key, and that the keys in \cite{key} in the body match them.

  6. 6Verify the packages required by math environments are loaded

    \usepackage{amsmath}

    align/equation depend on amsmath; without it they report an undefined environment.

Command Examples

A minimal paper skeleton: title, TOC and sections

\documentclass{article} \usepackage[utf8]{inputenc} \usepackage{amsmath} \title{Report Title} \author{Author} \date{\today} \begin{document} \maketitle \tableofcontents \section{Introduction} First paragraph of body text; \textbf{bold} and \texttt{monospace} both come from packages already loaded in the preamble. \subsection{Background} \begin{itemize} \item Point one \item Point two \end{itemize} \end{document}

Everything before \begin{document} is preamble: packages and title metadata only; everything after it is body text. \maketitle renders the \title/\author/\date block on the first page, and \today stamps the build date so you never hand-edit it. Keep amsmath in the preamble, otherwise \begin{equation} fails with an undefined environment error.

Math: inline, numbered, aligned and common symbols

Inline formula: $E = mc^2$ appears mid-sentence. Numbered equation whose number can be referenced in the body: \begin{equation} \frac{a}{b} = \sqrt{x} \label{eq:fraction} \end{equation} Multi-line aligned equation: \begin{align} \sum_{i=1}^{n} x_i &= \alpha + \beta \label{eq:sum} \\ \int_{a}^{b} f(x) \, dx &= \infty \partial \nabla \end{align} Unnumbered display formula: \[ E = mc^2 \]

equation numbers the formula so the body can pull it in with \ref{eq:fraction}; align handles multiple lines, where the trailing \\ on each line is mandatory and & sits before the equals sign to set the alignment column. Inline math uses $...$, unnumbered display math uses \[ ... \]. Ordinary spaces collapse inside math mode, so spacing has to come from the alignment environment rather than from typed blanks.

Tables: merged cells, float placement and a referenceable number

\begin{table}[htbp] \begin{tabular}{|c|c|c|} \hline a & b & c \\ \hline \multicolumn{2}{|c|}{Header spanning two columns} & d \\ \hline 1 & 2 & 3 \\ \hline \end{tabular} \caption{Summary of results} \label{tab:result} \end{table} In-text reference: see Table~\ref{tab:result}.

The column count is fixed by the column spec in \begin{tabular} ({|c|c|c|}), so every row needs exactly that many & separators, and the final row still needs a trailing \\ or it merges into whatever follows. \multicolumn{2}{|c|}{...} fuses two cells into one, and you repeat the vertical rules on both sides. The number comes from \caption, and \label has to sit immediately after it for the cross-reference to resolve.

Figures, subfigures and the full bibliography chain

\usepackage{graphicx} \begin{figure}[htbp] \includegraphics[width=0.5\textwidth]{pipeline.png} \caption{Overall pipeline} \label{fig:pipeline} \end{figure} \begin{figure}[htbp] \begin{subfigure} \includegraphics[width=0.45\textwidth]{stage-a.png} \caption{Stage A} \end{subfigure} \begin{subfigure} \includegraphics[width=0.45\textwidth]{stage-b.png} \caption{Stage B} \end{subfigure} \caption{Two-stage comparison} \label{fig:stages} \end{figure} In-text: Figure~\ref{fig:pipeline} and Figure~\ref{fig:stages}. \bibliographystyle{plain} \bibliography{references}

The subfigure environment requires the subcaption package in the preamble, otherwise LaTeX reports that it cannot find the environment. Keep image paths to lowercase letters, digits and hyphens: a filename with spaces or non-ASCII characters silently loses the figure on another machine. The argument to \bibliography is the references.bib sitting next to the source, and a missing bib file does not stop the build, it just quietly produces an empty bibliography.

Common Pitfalls

  • A percent sign in running text is a comment marker: everything after it on that line is silently dropped, including words and commands that were supposed to appear in the PDF. Underscore, hash, dollar sign and ampersand must be written as their control sequences; typing the raw character either mangles the layout or stops the whole build.
  • Deliver after a single pass and every \ref prints ?? with an empty table of contents, and after reordering sections any hard-coded figure numbers no longer match the references in the text. Cross-references must go through \label plus \ref and need two passes after the auxiliary files are cleared.
  • When the .bib named by \bibliography{references} was never committed, is caught by .gitignore, or is simply mistyped, LaTeX does not error: the bibliography disappears and only [?] remains, so reviewers receive a draft with no references at all.
  • An \includegraphics path containing spaces or non-ASCII characters builds fine locally and turns into an empty placeholder box on another machine or in CI, so the figure is gone while the build stays green. Keep filenames to lowercase letters, digits and hyphens.
  • A long table placed in tabular overflows the text block horizontally and gets trimmed off the page, and LaTeX will not stop you; content taller than one page inside a float is pushed elsewhere, sometimes after the bibliography. Use a page-spanning environment for long tables instead of shrinking the font to force them in.

Tips

  • Use \left( and \right) in math to auto-size parentheses.
  • Float placement [htbp]: h here, t top, b bottom, p separate page.
  • Use \label and \ref for cross-references instead of hardcoding numbers.

FAQ

What are the essential LaTeX commands?

By purpose: structure uses \documentclass, \begin{document}/\end{document} and \section; text uses \textbf, \emph and \verb; math uses $...$ inline and $$...$$ display, \frac, \sum; lists use itemize/enumerate; tables use tabular; references use \cite with BibTeX/biblatex. This page groups copy-ready snippets.

How do I insert math formulas in LaTeX?

Inline math uses a single dollar pair like $E=mc^2$; display math uses double dollars $$...$$ or the equation environment. Use equation when you want a number, double dollars when you do not.

How do I add references in LaTeX?

Cite with \cite{key} in the body and print the list at the end with \bibliography{filename} or biblatex’s \printbibliography; entries live in a .bib file. Compile with BibTeX or biblatex to generate the list.

How do I quickly locate a LaTeX compile error?

Read the first error line in the compiler log — most issues (missing package, unclosed environment, unescaped special char) point at a specific line. Build a minimal compilable skeleton first, then add content, rather than editing heavily right before the deadline.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us