# How to cross-reference an inequality with \cref?

I have inequalities being cross-referenced by \cref as equations.

1-) How can I change that? (and still have inequalities with the same numbering as equations)

2-) How can I change that and have inequalities with their own numbering?

\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{cleveref}
\usepackage[letterpaper]{geometry}
\begin{document}

\begin{flalign}
&f(x) \geq g(x)& \label{i:positivity}
\end{flalign}

Admitting that \cref{i:positivity} has a solution, ...

\end{document}

• Why not use \eqref{}? – Sigur Jul 11 '14 at 1:44
• This solves. But since I was using cref to automatically handle all the different types of references, I was wondering if this would still be doable using it. – capadocia Jul 11 '14 at 1:51
• @Sigur - Assume the hyperref package is loaded and cleveref was loaded with the option nameinlink. By writing "by inequality \eqref{xyz}" instead of "by \cref{xyz}", one loses the feature of having the word "inequality" be part of the "target" of the hyperlink. – Mico Jul 11 '14 at 7:29

Assuming you want to use the same counter variable for both equation-like and inequality-like environments, you can proceed by informing cleveref (i) that certain environments are "special" (specifically, that they are inequalities) and (ii) what to do in terms of typesetting the cross-references to these "special" objects. The former can be achieved by providing an optional argument to the \label command. (cleveref cleverly redefines \label to make this possible.) The latter can be achieved by executing appropriate \crefname and \creflabelformat instructions.

\documentclass[12pt,letterpaper]{article}
\usepackage{amsmath,geometry}
\usepackage[colorlinks]{hyperref} %%  just for this example

\crefname{ineq}{inequality}{inequalities}
\creflabelformat{ineq}{#2{\upshape(#1)}#3}
%% \upshape ensures that the number and surrounding parens are typeset in upright mode

\setlength\parindent{0pt} %%  just for this example
\setlength\textwidth{4in} %%  just for this example

\begin{document}
\begin{flalign}
&f(x) \geq g(x)& \label[ineq]{i:positivity} %% note optional argument of \label
\end{flalign}
Admitting that \cref{i:positivity} has a solution, \dots
\end{document}


Section 6 of the user guide of the cleveref package provides a fuller explanation of how this works. In that section, it's also explained how to automate this a bit if you have lots and lots of inequalities, in which case it might become tedious to have to remember to supply the option ineq to \label whenever the object is an inequality.

• Did you mean to write either \textup{(#1)} or {\upshape(#1)} where you used \upshape{(#1)}? – Crissov Jul 11 '14 at 8:46
• @Crissov - Good catch: It should be {\upshape(1)}. I'll edit the code accordingly. – Mico Jul 11 '14 at 14:31