# How to remove “figure” in \ref

I use my friend's template, and I try to create a figure in my document

\begin{figure}
\caption{abc}
\includegraphic{aaaaa.jpg}
\label{abc}
\end{figure}
\ref{abc}


I have "Figure I.1 abc" as figure caption (I is chapter number and 1 is figure number".

The problem is: when I ref the figure, I have "Figure I.1" instead of "I.1" only. I want "I.1" only without the word figure in \ref. How can I erase "figure" words in \ref?

I see the document class and found this code

\renewcommand \thefigure
{\ifnum \c@chapter>\z@ \figurename\ \thechapter.\fi \@arabic\c@figure}
\def\fnum@figure{\nobreakspace\thefigure}


The document class use nohyperref package.

• Welcome to TeX.SX! Have you load the cleverref package? The easiest you can do for helping us help you is to post a minimal working example (MWE) – ebosi Nov 29 '16 at 9:22
• If not redefined, \ref{label} should print I.1 only, that's why it will be easier to tell you why this is happening if we see what's in your code – ebosi Nov 29 '16 at 9:36
• Presumably this was done to put "Figure I.1" in the list of figures. To preserve that feature, you will have to modify \label (or more specifically \@currentlabel). – John Kormylo Nov 29 '16 at 15:01

What you request is actually the default behaviour if nothing is changed. So, my suggestion would be to revert back to the default definitions:

\documentclass{report}

\renewcommand{\thechapter}{\Roman{chapter}}

\makeatletter
% Default definitions for \thefigure and \fnum@figure
\renewcommand\thefigure
{\ifnum \c@chapter>\z@ \thechapter.\fi \@arabic\c@figure}
\renewcommand{\fnum@figure}{\figurename\nobreakspace\thefigure}
\makeatother

\begin{document}

\setcounter{chapter}{6}

This is a reference to Figure~\ref{test}.

\begin{figure}
\caption{A figure caption.}\label{test}
\end{figure}

\end{document}


Note the difference in the default definitions of \thefigure and \fnum@figure compared to yours: \figurename is removed from \thefigure and placed in \fnum@figure. This effectively keeps the formatting in the \caption the same, but removes it from the \reference (which uses \thefigure), as required.

It should be noted that without additional modifications (presumably in the unnamed document class) the list of figures is unreadable.

This fix requires adding \fixlabel between \caption and \label in every figure.

\documentclass{report}
\makeatletter
\renewcommand{\thechapter}{\Roman{chapter}}

\renewcommand \thefigure
{\ifnum \c@chapter>\z@ \figurename\ \thechapter.\fi \@arabic\c@figure}
\def\fnum@figure{\nobreakspace\thefigure}

\newcommand{\fixlabel}{\def\@currentlabel{\thechapter.\arabic{figure}}}
\makeatother

\begin{document}
\setcounter{chapter}{1}
\begin{figure}
\caption{Some caption}\fixlabel\label{test}
\end{figure}
This is a reference to \ref{test}.
\end{document}


You can provide a macro \Customfigurename{<Argument1>}{<Argument2>} where the phrase "Figure" that comes from \thefigure's expansion is exchanged by <Argument1> in text that is provided as <Argument2>. <Argument2> can as well contain things like \ref{abc} and <Argument1> can be empty which suppresses the phrase "Figure".

Not just suppressing the phrase but offering the possibility of providing another phrase makes sense when using the hyperref package while that other phrase is to be part of the hyperlink created by the hyperref package from the reference.

\documentclass{book}
%\usepackage{hyperref}

\makeatletter
\newcommand\Figurenamecustom{}%
\DeclareRobustCommand\Figurenamecustom{\@firstofone}%
\newcommand\Customfigurename{}%
\DeclareRobustCommand\Customfigurename[2]{%
\begingroup
\DeclareRobustCommand\Figurenamecustom[1]{#1}%
#2%
\endgroup
}%
\renewcommand\thefigure{%
\ifnum \c@chapter>\z@ \Figurenamecustom{\figurename\ }\thechapter.\fi
\@arabic\c@figure
}%
\def\fnum@figure{\nobreakspace\thefigure}
\makeatother

\begin{document}

\chapter{A Chapter}

\begin{figure}
\caption{abc}
%\includegraphic{aaaaa.jpg}
\rule{2cm}{2cm}%
\label{abc}
\end{figure}

\noindent \verb|\ref{abc}| yields:
\ref{abc}

\noindent \verb|\Customfigurename{}{\ref{abc}}| yields:
\Customfigurename{}{\ref{abc}}

\noindent \verb|\Customfigurename{funny figure~}{\ref{abc}}| yields:
\Customfigurename{funny figure~}{\ref{abc}}

\noindent \verb|\thefigure| yields:
\thefigure

\noindent \verb|\Customfigurename{funny figure~}{\thefigure}| yields:
\Customfigurename{funny figure~}{\thefigure}

\noindent \verb|\Customfigurename{}{\thefigure}| yields:
\Customfigurename{}{\thefigure}

\end{document}