The cleveref package

Writes the kind of object in front of a reference: \cref{fig:setup} prints "fig. 1" and handles several labels at once.

Loading the package

\usepackage{cleveref}

\ref prints only the number, so the word "Figure", "Table" or "Section" has to be typed in front of every reference. \cref knows which counter a label belongs to and adds the word itself. When a figure becomes a table, the text follows.

Several labels can go into one command. \cref{eq:a,eq:b,eq:c} sorts them and prints "eqs. (1) to (3)".

The names come in the language given as package option or as class option, for example ngerman. With \crefname you set your own names.

Main commands

\cref{fig:setup}Reference with name, for use inside a sentence.
\Cref{fig:setup}The same with a capital letter and without abbreviation, for the start of a sentence.
\cref{eq:a,eq:b,tab:data}Several labels, also of different kinds; no spaces after the commas.
\crefrange{eq:first}{eq:last}A range, such as "eqs. (1) to (5)".
\cpageref{fig:setup}Page reference with the word "page".
\crefname{equation}{Eq.}{Eqs.}Sets singular and plural name for one kind of object.
\usepackage[capitalise,noabbrev]{cleveref}capitalise writes all names with a capital letter, noabbrev writes them out in full.
\usepackage[nameinlink]{cleveref}With hyperref: the name is part of the link, not only the number.

Complete example

\documentclass{article}
\usepackage{amsmath}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\section{Model}\label{sec:model}
\begin{equation}\label{eq:force}
  F = m a
\end{equation}
\begin{equation}\label{eq:energy}
  E = \tfrac{1}{2} m v^2
\end{equation}
\Cref{eq:force,eq:energy} belong to \cref{sec:model}.
See also \cpageref{eq:energy}.
\end{document}
Result
The compiled example

Open in the editor

Compiled with pdfLaTeX from TeX Live 2023. Tools run in this order: pdflatex → pdflatex.

Pitfalls

Related pages