11

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}
3
  • 1
    Why not use \eqref{}?
    – Sigur
    Jul 11, 2014 at 1:44
  • 1
    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.
    – Ararat
    Jul 11, 2014 at 1:51
  • 1
    @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, 2014 at 7:29

1 Answer 1

14

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.

enter image description here

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

\usepackage[nameinlink]{cleveref} 
\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.

5
  • 2
    Did you mean to write either \textup{(#1)} or {\upshape(#1)} where you used \upshape{(#1)}?
    – Crissov
    Jul 11, 2014 at 8:46
  • @Crissov - Good catch: It should be {\upshape(1)}. I'll edit the code accordingly.
    – Mico
    Jul 11, 2014 at 14:31
  • The 10th upvote on this answer not only awarded me a "good answer" bronze badge, but badge #1,500 overall on this site! Many thanks!!
    – Mico
    Sep 14, 2020 at 17:52
  • Why is {\upshape(#1)} preferable to \textup{(#1)}?
    – Evan Aad
    Dec 6, 2022 at 16:57
  • 2
    @EvanAad - I don't think that I claimed that {\upshape(#1)} was preferable to \textup{(#1)}. User Crissov pointed out that \upshape{(#1)} was wrong and gave me two alternatives, both of which are corrrect. I'm guessing that since the code already contained \upshape, it was less editing work for me to choose {\upshape(#1)} than \textup{(#1)}. To be honest, though, since this episode occurred more than 8 years ago, I'm not really sure now what exactly my thought process was at the time.
    – Mico
    Dec 6, 2022 at 17:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .