43

I've always used \ref for referring to labelled items, but a LaTeX template I downloaded uses \autoref instead. What is the difference?

  • 2
    Is one of our answers useful to you or do you want more explanations? – Ludovic C. Oct 15 '13 at 19:03
48

\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>}
  • 6
    What is the difference between this and cleveref ? :) – Ciprian Tomoiagă Feb 22 '18 at 11:06
37

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}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.