3

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

1
  • Welcome to TeX.SE. Should the counter associated with the "Example" float be the same as the counter associated with "figure" floats? I.e., should the numbering go like Figure 5, Figure 6, Example 7, Figure 8, Figure 9, etc? Please advise.
    – Mico
    Dec 11, 2016 at 15:53

3 Answers 3

1

\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}
    
0

I'd like to propose that you use the facilities of the cleveref package to achieve your typesetting objective. You should

  • load the cleveref package with the options nameinlink, noabbrev, and capitalize; this will make the output of \cref look like that of autoref. (Note: cleveref must be loaded after hyperref.)

  • provide the optional argument example to the \label instruction:

    \label[example]{fig:xyz}
    

Of course, keep issuing the instruction \renewcommand\figurename{Example} inside the figure environment, as per the earlier solution.

No other changes required.

enter image description here

\documentclass{article}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\begin{document}

\setcounter{figure}{7} % just for this case
\begin{figure} 
\renewcommand\figurename{Example} % as per the earlier solution
\centering
ABC
\caption{This is an example.} 
\label[example]{fig:xyz}  % note the optional argument: "example"
\end{figure}

A cross-reference to \cref{fig:xyz}.
\end{document}
0

You might consider defining a new float type.

FYI, \floatname defines \fname@example which is used by \caption.

\documentclass{article}
\usepackage{float}% for \newfloat
\usepackage{hyperref}

\newfloat{example}{htbp}{lox}
\floatname{example}{Example}
\newcommand{\examplename}{Example}

\begin{document}
\begin{example} 
   \caption{This is an example.}\label{test}
\end{example}

\autoref{test}
\end{document}

You must log in to answer this question.

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