# Changing the way figure reference appears in LaTeX

How can one make LaTeX insert Figure into \ref calls automatically, i.e. instead of writing:

See data in Figure ~\ref{fig:JobInformationDialog}

simply write:

See data in \ref{fig:jobInformationDialog}

and have LaTeX insert Figure [fignum] when it gets compiled?

## migrated from stackoverflow.comMay 13 '14 at 17:31

This question came from our site for professional and enthusiast programmers.

A very easy way is provided by the prettyref package:

\documentclass{article}
\usepackage{caption}
\usepackage{prettyref}
\newrefformat{fig}{Figure~[\ref{#1}]}

\begin{document}

\begin{center}
\rule{10cm}{2cm}
\captionof{figure}{This is my caption}
\label{fig:first}
\end{center}

\end{document}


hyperref provides \autoref which automatically sets a title with every reference. For figures, this is Figure:

\documentclass{article}
\usepackage{hyperref}

\begin{document}

\begin{figure}[ht]
\centering\rule{10cm}{2cm}
\caption{This is my caption}
\label{fig:first}
\end{figure}

\end{document}


The starred version \autoref* removes the internal document hyperlinking for that specific link only.

The cleveref package provides macros \cref and \Cref that do exactly this, in a very configurable way (see documentation):

\documentclass{article}
\usepackage{hyperref,cleveref}

\begin{document}

\begin{figure}[ht]
\centering\rule{10cm}{2cm}
\caption{This is my caption}
\label{fig:first}
\end{figure}


Using hyperref is optional, but it should be loaded before cleveref.