[Tex/LaTex] Change autoref and caption name for only one figure

autorefcaptionsexamplesfloats

I saw in Change figure caption name only in one figure, not all how to change the caption name for only one figure but I need to change de autoref name too.

Using

\begin{figure} 
   \renewcommand\figurename{Example}
      ....
      \caption{This is an example.}
\end{figure}

The figure caption change for "Example" but in te autoref it said "Figure".

How can I override figurename and autorefname for only one figure?

Thanks

Best Answer

\autoref uses the counter name in the anchor name to get the term for the reference.

There are various workarounds.

The figure:

\begin{figure}
  \renewcommand*{\figurename}{Example}
  ...
  \caption{This is an example.}
  \label{exp}
\end{figure}

Workarounds:

  • \ref instead of \autoref:

    Example~\ref{exp}
    
  • \ref instead of \autoref with including "Example" in the link:

    \hyperref[exp]{Example~\ref*{exp}}
    
  • Redefining \p@figure to include "Example" as prefix to the reference:

    \begin{figure}
      \makeatletter
      \renewcommand*{\p@figure}{Example~}
      \makeatother
      ... % see above
    \end{figure}
    
    \ref{exp}% -> Example <number>
    
  • New counter example:

    % preamble
    \newcounter{example}
    \def\exampleautorefname{Example}
    
    \begin{figure}
      \setcounter{example}{\value{figure}}
      \refstepcounter{example}
      \label{exp}
      ...
      \caption{This is an example.}
    \end{figure}
    
    \autoref{exp}