I recently came into contact with a LaTeX package that saves me quite a bit of time: the cleveref
package. This package is very easy to use, so I will start explaining things right away! But first, note that the hyperref
package provides something similar with the autoref command, but in my eyes the cleveref
package is more sophisticated.
Table of Contents
Setup
As always, the package is called in the preamble by writing \usepackage{cleveref}
. In your document, all you have to do is write \cref{...}
instead of figure~\ref{...}
. The cleveref
package will automatically detect where the reference is about and it will print the corresponding text (e.g. figure when you refer to a figure environment).
That’s it! … Well, there are some more things that might be handy to know so I’ll briefly go through them.
Capitalized references
As far as I know, the only time you want your references capitalized is on the start of a sentence. For some reason, a lot of my fellow students and colleagues capitalize every reference they make. This is not only wrong (right?), it also looks ugly… Anyway, to capitalize your references, use \Cref{...}
instead of \cref{...}
. Easy!
Multiple references
Another thing that is quite nice is that cleveref
allows multiple references with one command. For example, \cref{eq1,eq2}
prints ‘eqs. (1) and (2)‘. But that’s not all! When referencing to multiple environments (e.g. figures, equations and tables as in \cref{fig1,eq3,tb1}
), the package automatically prints the right names to the right references.
Editing the reference names
I like my references to be written out in full, but the cleveref package prints ‘eq. …‘ instead of ‘equation …‘. Again, this is easily changed:
\crefname{equation}{equation}{equations} |
In the first argument of \crefname{}{}{}
comes the type of reference (equation, figure, table, section, etc.). The second argument contains the word that is printed if only one reference is made and the third argument contains the plural form for multiple references.
More
There is more what you can do with this package, but I tried not to go in-depth. For more information I suggest you to take a look at the package documentation.