1

Usually when i use \ref for referring a figure, table, and equation, i only get the number. I mean, the only clickable part and shown on the document is the number. I want to include the name of the figure automatically. So, when i use \ref{} on my figure, i don't need to add text "Figure" manually before \ref{}. How to accomplish this?

To make my question clear, here is the example:

Raw input:

\documentclass{article}
\usepackage{graphicx, hyperref, caption}
\begin{document} 
 the data is shown in Figure \ref{fig:figure}. 
   \begin{figure}[htb]
       \centering
       \includegraphics{figure1} 
       \caption{This is a figure}
       \label{fig:figure} 
    \end{figure}
 \end{document}

As you can see there, i still need to add "Figure" text manually. I wish i can include the name of the figure on the output by just using \ref{fig:figure}

1 Answers1

2

With the help of the cleveref package. The output can of course be adjusted to suit your needs. If you want \cref to output "figure" instead of "fig.", add the noabbrev option to the cleveref package.

Side note on the load order of packages in the preamble: Most of the times, the load order does not matter, but here it does. Generally, the hyperref package should be the last package in your preamble, with a few exceptions, such as cleveref, which in turn should be loaded after hyperref.

enter image description here

\documentclass{article}
\usepackage{graphicx, caption}
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}

with ref: Figure \ref{fig:figure}

with cref: \cref{fig:figure} (For the use in the middle of a sentence) %If you don't want "fig.", but "figure", add the noabbrev to the cleveref package.

with Cref: \Cref{fig:figure} (For the use as the beginning of a sentence)

\begin{figure}[htb] \centering \includegraphics{example-image} \caption{This is a figure} \label{fig:figure} \end{figure} \end{document}

leandriis
  • 62,593
  • Hi, thanks for the answer, i've tried this but the only clickable part is the number. My figurename is renewed as "Gambar" in my preamble. But the output is in English. – user516076 Jan 17 '21 at 10:08
  • To also include the word figure into the hyperlink, use the nameinlink option. What does "My figurename is renewed as "Gambar" in my preamble" mean? What language is your text written in? – leandriis Jan 17 '21 at 10:12
  • In case the language you are writing in is not already supported, you can use \crefname{〈type〉}{〈singular〉}{〈plural〉} and \Crefname{〈type〉}{〈singular〉}{〈plural〉} in the preamble of the document to provide the correct words. – leandriis Jan 17 '21 at 10:19
  • it's work, but the name of the label "Gambar" is not clickable – user516076 Jan 17 '21 at 10:51
  • Did you add the nameinlik option as in \usepackage[nameinlink]{cleveref}? – leandriis Jan 17 '21 at 10:54
  • Ok now it's work. Thank you so much for the help!! – user516076 Jan 17 '21 at 11:00