LaTeX quick reference

Dense one-page card for skeleton, text, math, floats, cites, layout, engines, TikZ, Beamer, and common log errors.

LaTeX quick reference

Keep this next to the editor. Every row is paste-ready. For longer lessons, open the matching track on Learn.

Jump: Skeleton · Preamble · Text · Sections · Refs · Math · Tables · Figures · Cites · Layout · Engines · TikZ · Beamer · Theorems · Fields · Compile · Errors · Package order

Document skeleton

\documentclass[11pt,a4paper]{article} % or report, book, beamer
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{graphicx,booktabs}
\usepackage{xcolor}
\usepackage[colorlinks=true,linkcolor=blue,citecolor=blue,urlcolor=blue]{hyperref}
% \usepackage[backend=biber,style=numeric]{biblatex}
% \addbibresource{refs.bib}
\title{Title}
\author{Your Name}
\date{\today}
\begin{document}
\maketitle
\begin{abstract} ... \end{abstract}
\tableofcontents
\section{Introduction}
...
% \bibliographystyle{plain}\bibliography{refs} % BibTeX
% \printbibliography % biblatex
\end{document}
ClassTypical use
articlePapers, notes, homework
reportLonger reports with chapters
bookBooks / many theses
beamerSlides
University .clsThesis templates
FileRole
.texSource
.bibBibliography database
.cls / .styClass / package
.aux .log .tocGenerated; do not edit

Preamble patterns

\usepackage[margin=1in]{geometry}
\usepackage{setspace}\onehalfspacing
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{siunitx} % units and numbers
\usepackage{cleveref} % after hyperref
\DeclareMathOperator*{\argmax}{arg\,max}
\newcommand{\vect}[1]{\boldsymbol{#1}}

Load hyperref late. Load cleveref after hyperref.

Text and formatting

WantType
Bold / italic / mono\textbf{} \textit{} \texttt{}
Emphasis (nests)\emph{}
Small caps\textsc{}
Underline (rare)\underline{}
Sizes{\small } {\large } {\Large } {\footnotesize }
New paragraphblank line
Line break\\ or \newline
Non-breaking space~
Horizontal space\quad \qquad \hspace{1em}
Vertical space\vspace{1em} \bigskip
Center / flushcenter / flushright environments
Quotequote or quotation
Footnote\footnote{...}
Comment% rest of line

Escape specials (text mode)

CharCodeCharCode
%\%$\$
&\&#\#
_\_{ }\{ \}
~\textasciitilde^\textasciicircum
\\textbackslash

Lists

\begin{itemize}
\item Bullet
\end{itemize}
\begin{enumerate}
\item Numbered
\end{enumerate}
\begin{description}
\item[Term] Definition
\end{description}

Custom label: \item[(a)] ...

Page numbers and breaks

WantType
Style\pagestyle{plain} / empty / fancy
This page only\thispagestyle{empty}
Roman / arabic\pagenumbering{roman} then arabic
New page\newpage \clearpage
Soft break request\pagebreak[3]
Keep together\nopagebreak

Sectioning and structure

\part{...} % book
\chapter{...} % report/book
\section{...}
\subsection{...}
\subsubsection{...}
\paragraph{...}
\section*{Unnumbered}
\addcontentsline{toc}{section}{Unnumbered}
WantType
TOC\tableofcontents
List of figures/tables\listoffigures \listoftables
Abstract\begin{abstract}...\end{abstract}
Appendix\appendix then \section / \chapter
Multi-file\include{chapters/intro} or \input{...}
Draft one chapter\includeonly{chapters/methods}
\section{Methods}\label{sec:methods}
\begin{equation}\label{eq:main} E=mc^2 \end{equation}
\begin{figure}
...
\caption{Pipeline}\label{fig:pipe}
\end{figure}
See Section~\ref{sec:methods}, Eq.~\eqref{eq:main}, Figure~\ref{fig:pipe}.
% with cleveref:
% \cref{fig:pipe} \Cref{sec:methods}
\usepackage{hyperref}
\url{https://oleafly.com}
\href{https://oleafly.com}{Oleafly}
\hypersetup{pdftitle={My Paper}, pdfauthor={You}}

Put \label after \caption so the number is correct.

Math mode

WantType
Inline$...$ or \( ... \)
Display unnumbered\[ ... \]
Display numberedequation + \label
Multi-line alignedalign / align*
Centered multi-linegather / gather*
One number, many linesequation + split
Long broken linemultline
Suppress one number\notag or \nonumber
Reference\ref{eq:x} or \eqref{eq:x}
\begin{align}
a &= b + c \label{eq:a} \\
d &= e + f \notag
\end{align}

Fractions, roots, scripts

\frac{a}{b} \dfrac{a}{b} \tfrac{a}{b}
\sqrt{x} \sqrt[n]{x}
x_i x^{2n} x_{ij}^{2}
f' f'' \dot{x} \ddot{x}

Greek (math mode)

\alpha \beta \gamma \delta \epsilon \varepsilon \zeta \eta
\theta \vartheta \iota \kappa \lambda \mu \nu \xi
\pi \varpi \rho \varrho \sigma \varsigma \tau \upsilon
\phi \varphi \chi \psi \omega
\Gamma \Delta \Theta \Lambda \Xi \Pi \Sigma \Upsilon \Phi \Psi \Omega

Operators, relations, sets, arrows

\pm \mp \cdot \times \div \ast \star \circ \bullet
\leq \geq \neq \approx \equiv \sim \simeq \propto \ll \gg
\in \notin \subset \subseteq \supset \supseteq \cup \cap \emptyset
\to \mapsto \Rightarrow \Leftrightarrow \uparrow \downarrow
\infty \partial \nabla \ell \forall \exists \neg \land \lor

Accents and alphabets

\hat{x} \bar{x} \tilde{x} \vec{x} \dot{x} \ddot{x}
\widehat{xyz} \overline{ABC}
\mathbb{N Z Q R C} \mathcal{L} \mathfrak{g}
\mathrm{d}x \mathbf{A} \boldsymbol{\beta}

Big operators and calculus

\sum_{i=1}^n \prod_{i=1}^n \int_a^b \oint \iint
\lim_{x \to 0} \max_x \min_x \inf \sup
\frac{dy}{dx} \frac{\partial f}{\partial x}
\argmax_x % after \DeclareMathOperator*{\argmax}{arg\,max}

Matrices

\begin{pmatrix} a & b \\ c & d \end{pmatrix} % ( )
\begin{bmatrix} a & b \\ c & d \end{bmatrix} % [ ]
\begin{vmatrix} a & b \\ c & d \end{vmatrix} % | |
\begin{array}{r|cc} 1 & 2 & 3 \\ \hline 4 & 5 & 6 \end{array}

Piecewise

f(x) =
\begin{cases}
x^2 & x \ge 0 \\
-x & x < 0
\end{cases}

Delimiters

\left( \frac{a}{b} \right)
\left\{ x : x > 0 \right\}
\langle v, w \rangle
\lvert x \rvert \lVert v \rVert

Live preview: equation tool.

Tables

\usepackage{booktabs}
\begin{table}[htbp]
\centering
\caption{Results}\label{tab:res}
\begin{tabular}{lcc}
\toprule
Model & Acc & F1 \\
\midrule
Baseline & 0.81 & 0.79 \\
Ours & 0.87 & 0.86 \\
\bottomrule
\end{tabular}
\end{table}
WantType
Align columnsl c r p{3cm}
Vertical rule (avoid)`
Span columns\multicolumn{2}{c}{...}
Span rows\multirow{2}{*}{...} (multirow)
Multi-pagelongtable
Visual buildertable generator

Design habit: three horizontal rules, no vertical lines.

Figures and floats

\usepackage{graphicx}
\begin{figure}[htbp]
\centering
\includegraphics[width=0.8\textwidth]{figures/plot.pdf}
\caption{Overview.}\label{fig:plot}
\end{figure}
WantType
Widthwidth=0.5\textwidth or width=\linewidth
Heightheight=4cm (avoid both unless you must)
Page of PDFpage=2 option
Side by sidetwo minipages at 0.48\textwidth
Subfiguressubcaption package
Placement[htbp] (here, top, bottom, page)
Barrier\usepackage{placeins} + \FloatBarrier

Citations and bibliography

BibTeX (classic)

See \cite{knuth84} and \cite{a,b}.
\bibliographystyle{plain} % abbrv, alpha, ieeetr, apalike, ...
\bibliography{refs}

biblatex + biber

\usepackage[backend=biber,style=numeric]{biblatex}
\addbibresource{refs.bib}
...
\cite{knuth84} \parencite{knuth84} \textcite{knuth84}
\printbibliography

natbib

\usepackage{natbib}
\citet{key} % Author (year)
\citep{key} % (Author, year)
\citep*{key} % Author, year

Minimal .bib entry

@article{knuth84,
author = {Knuth, Donald E.},
title = {Literate Programming},
journal = {The Computer Journal},
year = {1984},
volume = {27},
pages = {97--111}
}

Validate: BibTeX validator.

SymptomFix
[?] or ?Wrong key, missing pass, or BibTeX vs Biber mismatch
Empty bibliographyPath, backend, or no \cite / wrong print command

Layout

\usepackage[a4paper,margin=1in]{geometry}
\usepackage{setspace}\onehalfspacing
\setlength{\parindent}{0pt}
\setlength{\parskip}{0.6em}
WantType
One-off no indent\noindent
Manual length\hspace{2em} \vspace{1ex}
Unitspt em ex cm mm in \textwidth \linewidth

Engines and packages

EngineGood for
pdfLaTeXMax journal compatibility
XeLaTeXSystem fonts, many scripts (fontspec)
LuaLaTeXModern Unicode + scripting
TectonicBundled / on-demand packages (Oleafly default)
% Xe/Lua
\usepackage{fontspec}
\setmainfont{Times New Roman}

Missing package (TeX Live): tlmgr install siunitx

Color

\usepackage{xcolor}
\textcolor{red}{warn}
\textcolor[HTML]{2563EB}{brand}
\definecolor{brand}{HTML}{2563EB}
\colorbox{gray!12}{highlight}

TikZ (minimal)

\usepackage{tikz}
\usetikzlibrary{positioning,arrows.meta}
\begin{tikzpicture}[node distance=1.4cm]
\node[draw,rounded corners] (a) {In};
\node[draw,rounded corners,right=of a] (b) {Out};
\draw[-Latex] (a) -- (b);
\end{tikzpicture}

Commutative diagrams: tikz-cd. Standalone export: \documentclass[tikz]{standalone}.

Beamer (minimal)

\documentclass{beamer}
\usetheme{Madrid}
\title{Talk}\author{You}
\begin{document}
\frame{\titlepage}
\begin{frame}{Results}
\begin{itemize}
\item<1-> First
\item<2-> Second
\end{itemize}
\pause
\end{frame}
\end{document}

Theorems

\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{lemma}[theorem]{Lemma}
\begin{theorem}[Name]
Statement.
\end{theorem}
\begin{proof}
...
\end{proof}

Field bits

% Chemistry
\usepackage[version=4]{mhchem}
\ce{H2O} \ce{CO2 + C -> 2CO}
% Physics
\usepackage{braket}
\braket{\psi|\phi} \braket{\psi|A|\phi}
% Code
\usepackage{listings}
\begin{lstlisting}[language=Python]
def f(x):
return x**2
\end{lstlisting}

Compile loop

  1. Edit .tex
  2. Run engine (pdfLaTeX / XeLaTeX / LuaLaTeX / Tectonic)
  3. If citations: BibTeX or Biber
  4. Run engine again (often twice) until ?? and TOC settle

In Oleafly, compile (or auto-compile) handles the loop; SyncTeX jumps between source and PDF.

Log errors (decode the first one)

SymptomUsual cause
Text vanishes mid-lineBare % started a comment
Missing $ inserted_ or ^ or math command in text
Undefined control sequenceTypo or missing package
File not foundWrong path / extension for input or image
References print ??Need another compile pass
Citations [?]Bad key, wrong backend, or missing bib pass
Empty bibliographyWrong \bibliography path or biblatex mismatch
Overfull \hboxUnbreakable line (URL, long math, no hyphen)
Emergency stopMissing \end{document}, bad include, runaway brace
Runaway argumentMissing } or \end{...}

Package load order (rules of thumb)

  1. Class options first
  2. Encoding / fonts
  3. Geometry, setspace, language
  4. Math, graphics, tables
  5. Domain packages
  6. hyperref near the end
  7. cleveref after hyperref
TrackStart
Open the loopFirst PDF
Equation craftMath mode · Symbols
FloatsTables · Images
CitationsAdd cites
Log literacyUndefined control sequence
Local studioOleafly workflow
Browser toolsEquation · Table · BibTeX

Full map: /learn/.

Back to Desk reference