# Undefined reference: autoref points to section instead of figure or table

Here is a minimum working example

(an image 'test.png' needs to be in the working directory. I used this one.)

% Created 2011-05-23 Mon 15:21
\documentclass[11pt]{article}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}

\section{figure test}
autoref test \autoref{fig:fig1}.

ref test \ref{fig:fig1}

\begin{figure}[hb]
\caption{test figure}
\label{fig:fig1}
\includegraphics[width=1in]{test.png}
\end{figure}

\section{table test}

autoref test \autoref{tab:tab1}.

ref test \ref{tab:tab1}

\begin{table}[hb]
\caption{test table}
\label{tab:tab1}
\begin{tabular}{ l c r }
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\end{tabular}
\end{table}

\end{document}


This is a snapshot of the output that I get:

## Questions:

How can I get the references to work?

Note: In my document, I am finding that the \autoref{fig:figurename} gives output as "item 1" instead of "figure 1". When making the MWE, the problems have changed, but I am still confused.

-
If you indent lines by 4 spaces, then they are marked as a code sample. You can also highlight the code and click the "code" button (with "101010" on it). –  Caramdir May 26 '11 at 19:23

The table reference isn't working because you are referencing tab:fig1, while the label is named tab:tab1.
The references are pointing to the section, because there is no caption (and hence no number) in your figure/table environment. Always have the \label after \caption.
thanks for the help. Works after compiling twice here as well. Putting the \label after the \caption solved my problem in the actual document as well. –  David May 26 '11 at 19:40