> ## Documentation Index
> Fetch the complete documentation index at: https://resources.latex-cloud-studio.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LaTeX Packages Reference

> Complete guide to essential LaTeX packages. Learn what each package does, how to use it, and see practical examples.

This reference covers the most important LaTeX packages organized by functionality. Each entry includes the package purpose, basic usage, and practical examples.

<Info>
  **Package installation**: LaTeX Cloud Studio includes all standard packages. No installation needed - just use `\usepackage{packagename}`.
</Info>

## Essential Packages

### Core Document Setup

<CodeGroup>
  ```latex essential-packages.tex theme={null}
  % Input encoding (for older documents)
  \usepackage[utf8]{inputenc}

  % Font encoding
  \usepackage[T1]{fontenc}

  % Language support
  \usepackage[english]{babel}
  % or multiple languages
  \usepackage[english,spanish,french]{babel}

  % Better fonts
  \usepackage{lmodern}

  % Microtype (better typography)
  \usepackage{microtype}
  ```
</CodeGroup>

### Page Layout

#### geometry

Controls page dimensions and margins.

<CodeGroup>
  ```latex geometry-package.tex theme={null}
  \usepackage{geometry}

  % Common configurations
  \geometry{margin=1in}
  \geometry{left=1.5in, right=1in, top=1in, bottom=1in}
  \geometry{a4paper, margin=2.5cm}
  \geometry{letterpaper, landscape}

  % Advanced options
  \geometry{
    paperwidth=210mm,
    paperheight=297mm,
    left=25mm,
    right=25mm,
    top=30mm,
    bottom=30mm,
    headheight=15pt,
    headsep=10mm,
    footskip=15mm
  }
  ```
</CodeGroup>

#### fancyhdr

Custom headers and footers.

<CodeGroup>
  ```latex fancyhdr-package.tex theme={null}
  \usepackage{fancyhdr}
  \pagestyle{fancy}

  % Clear defaults
  \fancyhf{}

  % Custom headers/footers
  \fancyhead[L]{Left Header}
  \fancyhead[C]{Center Header}
  \fancyhead[R]{\thepage}
  \fancyfoot[C]{Footer Text}

  % Different odd/even pages
  \fancyhead[LE,RO]{\thepage}
  \fancyhead[LO,RE]{\leftmark}

  % Custom styles
  \fancypagestyle{plain}{
    \fancyhf{}
    \fancyfoot[C]{\thepage}
  }
  ```
</CodeGroup>

## Mathematics Packages

### amsmath

Extended math environments and commands.

<CodeGroup>
  ```latex amsmath-package.tex theme={null}
  \usepackage{amsmath}

  % Provides environments:
  \begin{align}
    f(x) &= x^2 + 2x + 1 \\
    &= (x + 1)^2
  \end{align}

  \begin{gather}
    a = b + c \\
    d = e + f
  \end{gather}

  \begin{split}
    (a + b)^3 &= a^3 + 3a^2b \\
    &\quad + 3ab^2 + b^3
  \end{split}

  % Commands
  \text{text in math}
  \tfrac{a}{b}  % Text-style fraction
  \dfrac{a}{b}  % Display-style fraction
  \binom{n}{k}  % Binomial coefficient
  ```
</CodeGroup>

### amssymb

Additional mathematical symbols.

<CodeGroup>
  ```latex amssymb-package.tex theme={null}
  \usepackage{amssymb}

  % Provides symbols like:
  \mathbb{R}    % Real numbers
  \mathbb{Z}    % Integers
  \mathbb{N}    % Natural numbers
  \varnothing   % Empty set
  \therefore    % Therefore
  \because      % Because
  \blacksquare  % QED symbol
  \leqslant     % Less or equal (slanted)
  \geqslant     % Greater or equal (slanted)
  ```
</CodeGroup>

### amsthm

Theorem environments.

<CodeGroup>
  ```latex amsthm-package.tex theme={null}
  \usepackage{amsthm}

  % Define theorem environments
  \newtheorem{theorem}{Theorem}[section]
  \newtheorem{lemma}[theorem]{Lemma}
  \newtheorem{corollary}[theorem]{Corollary}

  \theoremstyle{definition}
  \newtheorem{definition}[theorem]{Definition}

  \theoremstyle{remark}
  \newtheorem{remark}[theorem]{Remark}

  % Usage
  \begin{theorem}[Fermat's Last Theorem]
  No three positive integers $a$, $b$, and $c$ satisfy...
  \end{theorem}

  \begin{proof}
  The proof is left as an exercise.
  \end{proof}
  ```
</CodeGroup>

### mathtools

Enhanced version of amsmath.

<CodeGroup>
  ```latex mathtools-package.tex theme={null}
  \usepackage{mathtools}

  % Additional features
  \begin{align}
    f(x) &= \begin{cases}
      x^2 & \text{if } x > 0 \\
      0 & \text{otherwise}
    \end{cases}
  \end{align}

  % Better spacing
  \coloneqq     % :=
  \Coloneqq     % ::=
  \eqqcolon     % =:

  % Paired delimiters
  \DeclarePairedDelimiter\abs{\lvert}{\rvert}
  \DeclarePairedDelimiter\norm{\lVert}{\rVert}

  % Usage
  \abs{x}      % Absolute value
  \abs*{x}     % Auto-sizing
  \norm{v}     % Vector norm
  ```
</CodeGroup>

## Graphics and Figures

### graphicx

Standard package for including graphics.

<CodeGroup>
  ```latex graphicx-package.tex theme={null}
  \usepackage{graphicx}

  % Include images
  \includegraphics{image.png}
  \includegraphics[width=5cm]{image.pdf}
  \includegraphics[height=3cm]{image.jpg}
  \includegraphics[scale=0.5]{image.eps}
  \includegraphics[width=0.8\textwidth]{image.svg}

  % Rotation and scaling
  \includegraphics[angle=90]{image.png}
  \rotatebox{45}{Rotated text}
  \scalebox{2}{Scaled text}
  \resizebox{5cm}{3cm}{Resized content}

  % Figure environment
  \begin{figure}[htbp]
    \centering
    \includegraphics[width=\textwidth]{plot.pdf}
    \caption{Important results}
    \label{fig:results}
  \end{figure}
  ```
</CodeGroup>

### subcaption

Create subfigures and subtables.

<CodeGroup>
  ```latex subcaption-package.tex theme={null}
  \usepackage{subcaption}

  \begin{figure}
    \centering
    \begin{subfigure}{0.45\textwidth}
      \includegraphics[width=\textwidth]{image1.png}
      \caption{First subplot}
      \label{fig:sub1}
    \end{subfigure}
    \hfill
    \begin{subfigure}{0.45\textwidth}
      \includegraphics[width=\textwidth]{image2.png}
      \caption{Second subplot}
      \label{fig:sub2}
    \end{subfigure}
    \caption{Combined figure}
    \label{fig:combined}
  \end{figure}

  % Reference subfigures
  See Figure~\ref{fig:sub1} and~\ref{fig:sub2}.
  ```
</CodeGroup>

### tikz

Powerful graphics creation.

<CodeGroup>
  ```latex tikz-package.tex theme={null}
  \usepackage{tikz}
  \usetikzlibrary{arrows.meta, positioning, shapes}

  % Simple drawing
  \begin{tikzpicture}
    \draw (0,0) -- (2,1) -- (1,2) -- cycle;
    \node at (1,1) {Center};
  \end{tikzpicture}

  % Complex diagram
  \begin{tikzpicture}[
    node distance=2cm,
    every node/.style={draw, circle}
  ]
    \node (A) {A};
    \node (B) [right=of A] {B};
    \node (C) [below=of A] {C};
    
    \draw[->] (A) -- (B);
    \draw[->] (A) -- (C);
    \draw[->] (B) -- (C);
  \end{tikzpicture}
  ```
</CodeGroup>

## Tables

### booktabs

Professional table formatting.

<CodeGroup>
  ```latex booktabs-package.tex theme={null}
  \usepackage{booktabs}

  \begin{table}[htbp]
    \centering
    \caption{Professional table}
    \begin{tabular}{lcc}
      \toprule
      Item & Quantity & Price \\
      \midrule
      Apples & 5 & \$2.50 \\
      Oranges & 3 & \$1.80 \\
      Bananas & 6 & \$3.00 \\
      \midrule
      Total & 14 & \$7.30 \\
      \bottomrule
    \end{tabular}
  \end{table}
  ```
</CodeGroup>

### array

Enhanced array and tabular environments.

<CodeGroup>
  ```latex array-package.tex theme={null}
  \usepackage{array}

  % New column types
  \newcolumntype{C}{>{\centering\arraybackslash}X}
  \newcolumntype{R}{>{\raggedleft\arraybackslash}X}

  % Advanced tables
  \begin{tabular}{>{\bfseries}l c r}
    \hline
    Bold Header & Center & Right \\
    \hline
    Row 1 & Data & Values \\
    Row 2 & More & Data \\
    \hline
  \end{tabular}
  ```
</CodeGroup>

### longtable

Tables spanning multiple pages.

<CodeGroup>
  ```latex longtable-package.tex theme={null}
  \usepackage{longtable}

  \begin{longtable}{lcc}
    \caption{Long table spanning pages} \\
    \toprule
    Column 1 & Column 2 & Column 3 \\
    \midrule
    \endfirsthead
    
    \multicolumn{3}{c}{{\tablename\ \thetable{} -- continued}} \\
    \toprule
    Column 1 & Column 2 & Column 3 \\
    \midrule
    \endhead
    
    \midrule
    \multicolumn{3}{r}{{Continued on next page}} \\
    \endfoot
    
    \bottomrule
    \endlastfoot
    
    % Table content
    Data & More & Values \\
    % ... many rows
  \end{longtable}
  ```
</CodeGroup>

## Bibliography and Citations

### biblatex

Modern bibliography management.

<CodeGroup>
  ```latex biblatex-package.tex theme={null}
  \usepackage[style=authoryear,backend=biber]{biblatex}
  \addbibresource{references.bib}

  % Citation commands
  \cite{key}              % (Author, Year)
  \parencite{key}         % (Author, Year)
  \textcite{key}          % Author (Year)
  \citeauthor{key}        % Author
  \citeyear{key}          % Year
  \footcite{key}          % Footnote citation
  \fullcite{key}          % Full citation

  % Multiple citations
  \parencite{key1,key2,key3}

  % Bibliography
  \printbibliography
  ```
</CodeGroup>

### natbib

Traditional bibliography package.

<CodeGroup>
  ```latex natbib-package.tex theme={null}
  \usepackage[authoryear,round]{natbib}

  % Citation styles
  \citet{key}     % Author (Year)
  \citep{key}     % (Author, Year)
  \citealt{key}   % Author Year
  \citealp{key}   % Author, Year
  \citeauthor{key}% Author
  \citeyear{key}  % Year

  % With page numbers
  \citep[p.~25]{key}
  \citep[see][p.~25]{key}

  % Bibliography
  \bibliographystyle{plainnat}
  \bibliography{references}
  ```
</CodeGroup>

## Lists

### enumitem

Customizable lists.

<CodeGroup>
  ```latex enumitem-package.tex theme={null}
  \usepackage{enumitem}

  % Customized itemize
  \begin{itemize}[label=\textbullet, itemsep=0pt]
    \item First item
    \item Second item
  \end{itemize}

  % Customized enumerate
  \begin{enumerate}[label=(\alph*), start=3]
    \item Third item (c)
    \item Fourth item (d)
  \end{enumerate}

  % Inline lists
  \begin{enumerate*}[label=(\roman*)]
    \item One \item Two \item Three
  \end{enumerate*}

  % Description lists
  \begin{description}[style=nextline]
    \item[Long term] Description on next line
    \item[Short] Inline description
  \end{description}
  ```
</CodeGroup>

## Code and Verbatim

### listings

Code listings with syntax highlighting.

<CodeGroup>
  ```latex listings-package.tex theme={null}
  \usepackage{listings}
  \usepackage{xcolor}

  % Configure style
  \lstset{
    language=Python,
    basicstyle=\ttfamily\small,
    keywordstyle=\color{blue},
    commentstyle=\color{green},
    stringstyle=\color{red},
    numbers=left,
    numberstyle=\tiny,
    breaklines=true,
    frame=single
  }

  % Inline code
  \lstinline{print("Hello")}

  % Code block
  \begin{lstlisting}[caption=Python example]
  def fibonacci(n):
      if n <= 1:
          return n
      return fibonacci(n-1) + fibonacci(n-2)
  \end{lstlisting}

  % External file
  \lstinputlisting[language=C]{code.c}
  ```
</CodeGroup>

### minted

Advanced syntax highlighting.

<CodeGroup>
  ```latex minted-package.tex theme={null}
  \usepackage{minted}

  % Inline code
  \mintinline{python}{print("Hello")}

  % Code block
  \begin{minted}[linenos,bgcolor=gray!10]{python}
  def quicksort(arr):
      if len(arr) <= 1:
          return arr
      pivot = arr[len(arr) // 2]
      left = [x for x in arr if x < pivot]
      middle = [x for x in arr if x == pivot]
      right = [x for x in arr if x > pivot]
      return quicksort(left) + middle + quicksort(right)
  \end{minted}

  % External file
  \inputminted{javascript}{script.js}
  ```
</CodeGroup>

### verbatim

Enhanced verbatim environments.

<CodeGroup>
  ```latex verbatim-package.tex theme={null}
  \usepackage{verbatim}

  % Basic verbatim
  \begin{verbatim}
  Raw text with $special% characters&
  \end{verbatim}

  % Comment out sections
  \begin{comment}
  This entire section is commented out
  and will not appear in the output.
  \end{comment}

  % Verbatim input from file
  \verbatiminput{file.txt}
  ```
</CodeGroup>

## Fonts and Typography

### fontspec

Modern font selection (XeLaTeX/LuaLaTeX).

<CodeGroup>
  ```latex fontspec-package.tex theme={null}
  \usepackage{fontspec}

  % Set main fonts
  \setmainfont{Times New Roman}
  \setsansfont{Arial}
  \setmonofont{Courier New}

  % Font features
  \setmainfont[
    Ligatures=TeX,
    Numbers=OldStyle
  ]{Minion Pro}

  % Custom font families
  \newfontfamily\myfont{Comic Sans MS}
  {\myfont This text uses Comic Sans}
  ```
</CodeGroup>

### microtype

Typography refinements.

<CodeGroup>
  ```latex microtype-package.tex theme={null}
  \usepackage{microtype}

  % Automatic improvements:
  % - Character protrusion
  % - Font expansion
  % - Kerning adjustments
  % - Tracking adjustments

  % Manual adjustments
  \textls[200]{Letter spaced text}
  \microtypesetup{expansion=false}
  ```
</CodeGroup>

## Cross-references

### hyperref

Hyperlinks and PDF features.

<CodeGroup>
  ```latex hyperref-package.tex theme={null}
  \usepackage{hyperref}

  % Configuration
  \hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,
    urlcolor=cyan,
    citecolor=green,
    pdfauthor={Author Name},
    pdftitle={Document Title},
    pdfsubject={Subject},
    pdfkeywords={keyword1, keyword2}
  }

  % Usage
  \href{https://example.com}{Link text}
  \url{https://example.com}
  \nolinkurl{https://example.com}

  % Internal links
  \hyperref[label]{text}
  \autoref{label}  % Automatic reference type
  ```
</CodeGroup>

### cleveref

Intelligent cross-referencing.

<CodeGroup>
  ```latex cleveref-package.tex theme={null}
  \usepackage{cleveref}

  % Better references
  \cref{eq:equation}     % Equation (1)
  \Cref{fig:figure}      % Figure 1
  \cref{sec:section}     % Section 2.1

  % Multiple references
  \cref{eq:1,eq:2,eq:3}  % Equations (1) to (3)
  \cref{fig:a,fig:b}     % Figures 1 and 2

  % Custom names
  \crefname{algorithm}{algorithm}{algorithms}
  \Crefname{algorithm}{Algorithm}{Algorithms}
  ```
</CodeGroup>

## Specialized Packages

### siunitx

Scientific units and numbers.

<CodeGroup>
  ```latex siunitx-package.tex theme={null}
  \usepackage{siunitx}

  % Numbers
  \num{123456.789}        % 123,456.789
  \num{1.23e-4}          % 1.23 × 10⁻⁴

  % Units
  \si{\meter\per\second}  % m/s
  \si{\kilo\gram}        % kg
  \si{\degree\celsius}    % °C

  % Numbers with units
  \SI{9.81}{\meter\per\second\squared}  % 9.81 m/s²
  \SI{25}{\degree\celsius}              % 25 °C

  % Ranges
  \SIrange{10}{20}{\celsius}            % 10 °C to 20 °C
  \numrange{1.2}{3.4}                   % 1.2 to 3.4

  % Tables
  \begin{tabular}{S[table-format=3.2]}
    \toprule
    {Values} \\
    \midrule
    1.23 \\
    45.67 \\
    890.12 \\
    \bottomrule
  \end{tabular}
  ```
</CodeGroup>

### algorithm2e

Algorithm pseudocode.

<CodeGroup>
  ```latex algorithm2e-package.tex theme={null}
  \usepackage[ruled,vlined]{algorithm2e}

  \begin{algorithm}[H]
    \SetAlgoLined
    \KwData{Array $A$ of $n$ elements}
    \KwResult{Sorted array $A$}
    
    \For{$i \leftarrow 1$ \KwTo $n-1$}{
      $key \leftarrow A[i]$\;
      $j \leftarrow i-1$\;
      
      \While{$j \geq 0$ \KwAnd $A[j] > key$}{
        $A[j+1] \leftarrow A[j]$\;
        $j \leftarrow j-1$\;
      }
      $A[j+1] \leftarrow key$\;
    }
    
    \caption{Insertion Sort}
    \label{alg:insertion-sort}
  \end{algorithm}
  ```
</CodeGroup>

### mhchem

Chemical formulas and equations.

<CodeGroup>
  ```latex mhchem-package.tex theme={null}
  \usepackage{mhchem}

  % Chemical formulas
  \ce{H2O}              % Water
  \ce{CaCl2}            % Calcium chloride
  \ce{H2SO4}            % Sulfuric acid

  % Chemical equations
  \ce{2H2 + O2 -> 2H2O}
  \ce{CaCO3 + 2HCl -> CaCl2 + H2O + CO2}

  % Reaction arrows
  \ce{A <=>> B}         % Equilibrium
  \ce{A ->[catalyst] B} % Catalyst
  \ce{A ->[\Delta] B}   % Heat

  % States of matter
  \ce{H2O(l)}           % Liquid
  \ce{NaCl(s)}          % Solid
  \ce{CO2(g)}           % Gas
  \ce{Na+(aq)}          % Aqueous
  ```
</CodeGroup>

## Layout and Formatting

### multicol

Multiple column layouts.

<CodeGroup>
  ```latex multicol-package.tex theme={null}
  \usepackage{multicol}

  % Two-column text
  \begin{multicols}{2}
    This text will be formatted in two columns.
    LaTeX automatically balances the columns.
  \end{multicols}

  % Three columns with separator
  \begin{multicols}{3}[\section{Three Column Section}]
    Content in three columns with a section header.
  \end{multicols}

  % Column break
  \begin{multicols}{2}
    First column content.
    \columnbreak
    Second column content.
  \end{multicols}
  ```
</CodeGroup>

### setspace

Line spacing control.

<CodeGroup>
  ```latex setspace-package.tex theme={null}
  \usepackage{setspace}

  % Document-wide spacing
  \singlespacing
  \onehalfspacing
  \doublespacing
  \setstretch{1.5}

  % Local spacing
  \begin{spacing}{1.8}
    This paragraph has 1.8 line spacing.
  \end{spacing}

  \begin{singlespace}
    This paragraph is single-spaced.
  \end{singlespace}

  \begin{doublespace}
    This paragraph is double-spaced.
  \end{doublespace}
  ```
</CodeGroup>

### parskip

Paragraph spacing without indentation.

<CodeGroup>
  ```latex parskip-package.tex theme={null}
  \usepackage{parskip}

  % Automatically sets:
  % - \parindent to 0pt
  % - \parskip to appropriate spacing
  % - Adjusts list environments

  % Manual control
  \setlength{\parskip}{1em}
  \setlength{\parindent}{0pt}
  ```
</CodeGroup>

## Package Management Tips

### Loading Order

<Warning>
  **Important package loading order:**

  1. **Font encoding**: `inputenc`, `fontenc`
  2. **Language**: `babel`, `polyglossia`
  3. **Fonts**: `lmodern`, `fontspec`
  4. **Math**: `amsmath`, `amssymb`, `mathtools`
  5. **Graphics**: `graphicx`, `tikz`
  6. **Tables**: `booktabs`, `longtable`
  7. **Bibliography**: `biblatex`, `natbib`
  8. **Cross-references**: `cleveref`, `hyperref` (load last)
</Warning>

### Common Conflicts

<CodeGroup>
  ```latex Package Conflicts theme={null}
  % Avoid these combinations:
  % \usepackage{subfigure}  % Old package
  % \usepackage{subcaption} % Use this instead

  % \usepackage{cite}       % Basic citations
  % \usepackage{natbib}     % Use this for advanced citations

  % \usepackage{hyperref}
  % \usepackage{cleveref}   % Load cleveref AFTER hyperref
  ```

  ```latex Safe Loading theme={null}
  % Recommended safe order:
  \usepackage[utf8]{inputenc}
  \usepackage[T1]{fontenc}
  \usepackage[english]{babel}
  \usepackage{lmodern}
  \usepackage{microtype}

  \usepackage{amsmath}
  \usepackage{amssymb}
  \usepackage{graphicx}
  \usepackage{booktabs}

  \usepackage[style=authoryear]{biblatex}
  \usepackage{hyperref}
  \usepackage{cleveref}
  ```
</CodeGroup>

## Quick Reference

### Most Used Packages

<CardGroup cols={3}>
  <Card title="Essential" icon="star">
    `amsmath` `graphicx` `hyperref` `geometry` `babel`
  </Card>

  <Card title="Typography" icon="font">
    `microtype` `setspace` `parskip` `fontspec` `lmodern`
  </Card>

  <Card title="Tables" icon="table">
    `booktabs` `array` `longtable` `multirow` `tabularx`
  </Card>

  <Card title="Bibliography" icon="book">
    `biblatex` `natbib` `cite` `apacite` `chicago`
  </Card>

  <Card title="Math" icon="square-root-variable">
    `amssymb` `amsthm` `mathtools` `siunitx` `physics`
  </Card>

  <Card title="Code" icon="code">
    `listings` `minted` `verbatim` `algorithm2e` `pseudocode`
  </Card>
</CardGroup>

## Deep-Dive Guides

* [BibLaTeX guide](/learn/latex/bibliography/biblatex-guide)
* [Natbib guide](/learn/latex/bibliography/natbib-guide)
* [Choosing citation styles](/learn/latex/bibliography/choosing-citation-styles)
* [Table of contents](/learn/latex/document-structure/table-of-contents)
* [Glossaries and acronyms](/learn/latex/document-structure/glossaries)
* [Indexes](/learn/latex/document-structure/indexes)
* [Hyperlinks](/learn/latex/document-structure/hyperlinks)
* [Align and multline environments](/learn/latex/mathematics/align-and-multline-environments)
* [Operators and spacing](/learn/latex/mathematics/operators-and-spacing)
* [Fractions and binomials](/learn/latex/mathematics/fractions-binomials)
* [Plotting with pgfplots](/learn/latex/figures/plotting-with-pgfplots)
* [Language setup pages](/learn/latex/languages/french)

***

<Info>
  **Need help choosing packages?** Check our [Package Management Guide](/learn/latex/package-management) for recommendations based on document type and field.
</Info>

## Start in LaTeX Cloud Studio

<CardGroup cols={2}>
  <Card title="Open in LaTeX Cloud Studio" icon="cloud" href="https://app.latex-cloud-studio.com/?utm_source=resources&utm_medium=card&utm_campaign=docs_open_app&utm_content=reference_packages_open_app">
    Write, compile, and iterate directly in your browser.
  </Card>

  <Card title="Start from Article Template" icon="file-text" href="/templates/article">
    Use a ready-made template, then adapt it to your content.
  </Card>
</CardGroup>
