logo

LaTeX Cheatsheet

This cheatsheet covers common LaTeX commands and environments for quick reference.

Document Structure

  • Document Class: Defines the type of document.

    \documentclass[options]{class}
    % Common classes: article, report, book, letter, beamer
    % Common options: 10pt, 11pt, 12pt, a4paper, letterpaper, twocolumn, landscape
    
  • Packages: Add functionality.

    \usepackage[options]{package}
    % Essential packages:
    \usepackage[utf8]{inputenc} % Input encoding (often default now)
    \usepackage[T1]{fontenc}    % Font encoding (better font handling)
    \usepackage{amsmath}      % Advanced math environments and symbols
    \usepackage{graphicx}     % Include images (\includegraphics)
    \usepackage{hyperref}     % Creates hyperlinks within the document (PDF)
    \usepackage{geometry}     % Customize page margins (e.g., \usepackage[margin=1in]{geometry})
    
  • Preamble: Area between \documentclass and \begin{document} for loading packages and setting definitions.

  • Document Body: Main content area.

    \begin{document}
    % Your content goes here
    \end{document}
    
  • Title, Author, Date:

    \title{My Document Title}
    \author{Your Name}
    \date{\today} % Or specify a date like \date{October 26, 2023}
    
    \begin{document}
    \maketitle % Displays the title/author/date block
    ...
    \end{document}
    

Basic Text Formatting

  • Bold: \textbf{text}
  • Italics: \textit{text}
  • Underline: \underline{text} (Often typographically discouraged)
  • Emphasis: \emph{text} (Context-aware italics/roman)
  • Typewriter: \texttt{text}
  • Small Caps: \textsc{text}
  • Font Sizes (Switches):
    • {\tiny ...}
    • {\scriptsize ...}
    • {\footnotesize ...}
    • {\small ...}
    • {\normalsize ...} (Default)
    • {\large ...}
    • {\Large ...}
    • {\LARGE ...}
    • {\huge ...}
    • {\Huge ...}
  • Paragraphs: Separate paragraphs with a blank line in the source code.
  • Line Break: \\ or \newline (Use sparingly; usually better to let LaTeX handle line breaks).
  • New Page: \newpage or \clearpage (flushes floats)

Sections and Structure

  • Chapters (Book/Report): \chapter{Chapter Title}
  • Sections: \section{Section Title}
  • Subsections: \subsection{Subsection Title}
  • Subsubsections: \subsubsection{Subsubsection Title}
  • Paragraphs: \paragraph{Paragraph Title} (Acts like a heading)
  • Subparagraphs: \subparagraph{Subparagraph Title}
  • Unnumbered Sections: Add * (e.g., \section*{Unnumbered Section})
  • Table of Contents: \tableofcontents (Requires 2-3 LaTeX compilations)
  • Abstract:
    \begin{abstract}
    Summary of your document.
    \end{abstract}
    

Lists

  • Unordered (Bullet):
    \begin{itemize}
      \item First item
      \item Second item
        \begin{itemize}
          \item Nested item
        \end{itemize}
    \end{itemize}
    
  • Ordered (Numbered):
    \begin{enumerate}
      \item First item
      \item Second item
    \end{enumerate}
    
  • Description (Labeled):
    \begin{description}
      \item[Label 1] Description text.
      \item[Word] Definition of the word.
    \end{description}
    

Math Mode

  • Inline Math: $ E = mc^2 $ or \( E = mc^2 \)
  • Display Math (Unnumbered): \[ \sum_{i=0}^{n} i = \frac{n(n+1)}{2} \]
  • Display Math (Numbered): (Requires amsmath)
    \begin{equation} \label{eq:euler}
    e^{i\pi} + 1 = 0
    \end{equation}
    
  • Unnumbered Equation: (Requires amsmath)
    \begin{equation*}
    \int_{-\infty}^{\infty} e^{-x^2} dx = \sqrt{\pi}
    \end{equation*}
    
  • Align Environment: (Requires amsmath) For aligning multiple equations.
    \begin{align}
    a &= b + c \\ \label{eq:align}
    d &= e + f + g
    \end{align}
    

Common Math Symbols/Commands

| Command | Symbol/Output | Notes | | :--------------------- | :------------------------------------ | :------------------------------------------------------ | ---------- | --- | | ^ | Superscript (x^2) | x^{10} for multiple characters | | _ | Subscript (x_1) | x_{ij} for multiple characters | | \frac{num}{den} | Fraction | | | \sqrt{expr} | Square root | \sqrt[n]{expr} for n-th root | | \sum, \int, \lim | Summation, Integral, Limit | Use _ and ^ for limits/bounds | | \alpha, \beta, ... | Greek letters | \Gamma, \Delta, ... for uppercase | | \sin, \cos, \log | Standard functions (roman) | | | \times, \cdot | Multiplication symbols | \times, \cdot | | \leq, \geq, \neq | Less/Greater than or equal, Not equal | \le, \ge, \ne are synonyms | | \infty | Infinity symbol | | | \dots, \cdots | Ellipsis (low, centered) | \vdots, \ddots for vertical/diag | | \{ \} | Curly braces | Need backslash: \{, \} | | \left( ... \right) | Auto-sizing parentheses | Also \left[, \right], \left\{, \right\}, \left | , \right | | | \mathbf{X} | Bold math symbols | | | \mathcal{L} | Calligraphic letters | | | \mathbb{R} | Blackboard bold (needs amsfonts) | Common for sets (R, C, N, Z) |

Figures & Tables

  • Including Figures: (Requires graphicx package)
    \begin{figure}[htbp] % Placement options: h=here, t=top, b=bottom, p=page of floats
      \centering % Center the figure
      \includegraphics[width=0.8\textwidth]{image_filename} % Include image (no extension needed usually)
      \caption{Caption text for the figure.}
      \label{fig:myfigure} % Label for cross-referencing
    \end{figure}
    
    • \includegraphics options: width=, height=, scale=, angle=
  • Basic Table:
    \begin{table}[htbp]
      \centering
      \caption{Caption text for the table.}
      \label{tab:mytable}
      \begin{tabular}{|l|c|r|} % Column spec: l=left, c=center, r=right, |=vertical line
        \hline % Horizontal line
        Header 1 & Header 2 & Header 3 \\ % Column headers, & separates columns, \\ ends row
        \hline
        Row 1, Col 1 & R1C2 & R1C3 \\
        Row 2, Col 1 & R2C2 & R2C3 \\
        \hline
      \end{tabular}
    \end{table}
    
    • \hline: Full horizontal line
    • \cline{i-j}: Partial horizontal line spanning columns i to j

Cross-Referencing

  • Labeling: Use \label{marker} inside figure, table, equation environments, or after \section, \item, etc.
    • Common prefixes: fig:, tab:, eq:, sec:, itm:
  • Referencing:
    • \ref{marker}: Prints the number (e.g., figure number, equation number, section number).
    • \pageref{marker}: Prints the page number where the label occurs.
    • Eq.~\eqref{eq:marker}: Prints equation number in parentheses (requires amsmath).
    • Requires 2-3 LaTeX compilations to resolve references correctly.

Bibliography (using BibTeX)

  1. Create a .bib file (e.g., references.bib) with entries like:

    @article{einstein1905,
      author  = {Albert Einstein},
      title   = {Zur Elektrodynamik bewegter K{\"o}rper},
      journal = {Annalen der Physik},
      volume  = {322},
      number  = {10},
      pages   = {891--921},
      year    = {1905},
    }
    
    @book{knuth1984texbook,
      author    = {Donald E. Knuth},
      title     = {The {\TeX}book},
      publisher = {Addison-Wesley},
      year      = {1984},
    }
    
  2. In your LaTeX document:

    • Cite sources: \cite{key} (e.g., \cite{einstein1905}). Multiple: \cite{key1, key2}.
    • Specify bibliography style (in preamble or before \bibliography): \bibliographystyle{plain} (Common styles: plain, unsrt, alpha, abbrv)
    • Generate bibliography: \bibliography{references} (Use the .bib filename without the extension)
  3. Compilation Process: pdflatex yourfile, bibtex yourfile, pdflatex yourfile, pdflatex yourfile.

Special Characters & Symbols

  • Reserved Characters: Need backslash \ to print: \# \$ \% \& \_ \{ \} \~ \^
  • Backslash: \textbackslash
  • Ellipsis: \dots (low) or \ldots
  • Dashes:
    • - Hyphen (e.g., well-known)
    • -- En-dash (e.g., pages 10--20)
    • --- Em-dash (e.g., Yes---absolutely!)
  • Quotes:
    • `` for opening double quotes (“)
    • '' for closing double quotes (”)
    • ` for opening single quote (‘)
    • ' for closing single quote (’)
  • Tilde: ~ (Non-breaking space, useful e.g., Fig.~1)
  • Degree Symbol: \textdegree (requires textcomp) or $^\circ$ (in math mode)
  • Euro Symbol: \texteuro (requires textcomp or specific font setup)

Comments

  • Use the percent sign %. Everything from % to the end of the line is ignored.
    This is normal text. % This is a comment and will not be shown.
    % This entire line is a comment.
    

Compilation

  • Common command-line compilers: pdflatex, xelatex, lualatex. pdflatex is the most traditional.
  • Compile multiple times (usually 2-3) to resolve references, table of contents, and bibliography correctly.