Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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:

enter image description here

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.

share|improve this question
    
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
add comment

1 Answer

up vote 7 down vote accepted

(This answer refers to the original code in the question.)

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.

share|improve this answer
    
I fixed the table reference and added a caption, but I am still getting a reference to the section. –  David May 26 '11 at 19:20
    
@David: Your code works for me (after compiling twice). –  Caramdir May 26 '11 at 19:23
    
The new code is working here too. As Caramdir said, compile it twice. –  Paulo Cereda May 26 '11 at 19:26
    
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
2  
For anyone else that comes here; the label needs to come after the caption without any command between label and caption. I had an \end{center} between my caption and label, which caused this same issue. –  lvleph Feb 10 '12 at 15:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.