I've always used \ref for referring to labelled items, but a LaTeX template I downloaded uses \autoref instead. What is the difference?
Asked
Active
Viewed 1.1e+01k times
83
Ludovic C.
- 8,888
Ref
- 831
- 1
- 6
- 3
-
4Is one of our answers useful to you or do you want more explanations? – Ludovic C. Oct 15 '13 at 19:03
2 Answers
96
\autoref is a command from the hyperref package which is used to have some automatic prefix added to the reference. For instance if you used \label{sec:intro} just after your command for the introduction section the \autoref{sec:intro} command will output "section X" with X being the good number.
Of course you can imagine that the prefix depends on the type of the object to which the label is linked. If it is a figure, it will output "figure" and so on.
Note that you can redefine the prefix for the autoref command associated to a given type of object. For instance for the sections use:
\def\sectionautorefname{New prefix for the sections}
More generally,
\def\<type>autorefname{<new name>}
Ludovic C.
- 8,888
-
23
-
2One difference is that
cleverefcapitalizes the first letter of the word at the beginning of the sentence, which is pretty useful. – Tommy Mar 17 '22 at 14:59
79
The difference is easy to see in the following example:
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\begin{table}\centering
\caption{foo}\label{foo}
\tabular{c}
foo\\\hline
bar\\\hline
\endtabular
\end{table}
\begin{table}\centering
\caption{bar}\label{bar}
\tabular{c}
foo\\\hline
bar\\\hline
\endtabular
\end{table}
See Table~\ref{foo} and
\autoref{bar}
\end{document}
