[Tex/LaTex] Table, Figure, and Listing prefixes

cross-referencingfloatslyx

Background

Using LyX and KOMA Script to author a technical manual.

Problem

The documents are strewn with the following references:

\ref{fig:Example-Database-Type}

When converted to PDF, this results in "1.1" for the figure number, whereas I would prefer it to read "Figure 1.1". Similarly, for Tables and Listings, they should read "Table 1.1" and "Listing 1.1", respectively.

Code

The caption code is:

\caption{\label{fig:Example-Query-Statement}Example Query Statement}

The reference code is:

\ref{fig:Example-Query-Statement}

The document preamble includes:

\usepackage{hyperref}

The result is: "The screen shot in 1.1 shows …"

The desired result is: "The screen shot in Figure 1.1 shows …"

Ideas

Tried:

\let\oldref=\ref
\renewcommand{\ref}[1]{Figure {\oldref{#1}}}

Tried:

\usepackage{fancyref}
\renewcommand{\ref}[1]{\fref{#1}}

Tried:

\usepackage{hyperref}

Question

How do you change the \ref command to include a \figurename prefix without having to edit (and thus duplicate) the code for every figure (that already has the \ref)?

Thank you!

Best Answer

Hyperref has autoref which takes care of this stuff. It is described briefly here.

This solution doesn't do exactly what you want. That is, it doesn't redefine \ref. But I'm not sure that's a great idea anyway. (weirdly \let\ref\autoref doesn't seem to do anything). So to have what you want, you need to do two things:

Add \usepackage{hyperref} to your preamble and then put \let\ref\autoref just after your \begin{document}

If you don't like the ugly coloured borders hyperref puts on your references see this. Alternatively, you can also add the nohyperref package after the hyperref package.

Hyperref causes lots of nasty package conflicts, so put it near the end of your preamble.