# Are there any dependencies causing my \ref to not compile?

I have learned that for labels and their respective references to compile and display correctly (for figures), it is necessary to have the \label{} after \caption{}, such as below:

Figure \ref{k2a}

\begin{figure}[h]
% \caption{Isothermal thick film.}
\begin{center}
\centering
\includegraphics[width= \columnwidth]{/home/userid/Research/Dissertation/2D/Periodic/k2a}
\caption{When $\lambda = \lambda_{max}$ and M=35.1, Pr=7.20, S=100, G=1/3, rupture takes place at t=1280.0 (within 1\% or\citet{Krishnamoorthy1995a})}
\label{k2a}
\end{center}
\end{figure}

However, are there any .sty / package dependencies that are not allowing my labels to compile right? I run latex twice but I receive a bunch of warnings such as Reference on page abc undefined on input line xxx. and I get the dreaded ? where the reference should be. The link to the figure through the question mark works though.

Here is my preamble, where I load all my packages. This occurs in a separate file.

does \usepackage{caption} have anything to do with this issue?

\usepackage{graphicx}
%\usepackage{float}
\usepackage[section]{placeins}
\usepackage{caption}
\captionsetup{margin=10pt,font=small,labelsep=period,labelfont=bf}
% --------
\usepackage{lscape}         % allows for landscape tables and figures
\usepackage{paralist}       % enancements to list environment
\usepackage{array}          % enhancements to array and tabular environments
\usepackage[usenames]{color}
\usepackage{url}
\usepackage{longtable}      % multipage tables
\usepackage{ifthen}
\usepackage{ifpdf}
\usepackage{setspace}       % easy single or doublespacing
\usepackage{amsmath,amsfonts,amssymb}
\usepackage{rotate}
\usepackage{subfigure}
\usepackage{subfig}
\usepackage{wrapfig}
\usepackage{listings}       % for listing computer code such as matlab
\usepackage[bw]{mcode}      % for matlab code with listings package
\usepackage[square,comma,sort&compress]{natbib} % enhances bibtex citations
% \usepackage{biblatex}
\usepackage{setspace}       % \singlespacing, \onehalfspacing, \doublespacing, ...

%%%%%%%%xyz%%%%%%%%%%%%%%%
\usepackage{epsfig}
\usepackage{epstopdf}
\usepackage{textcomp}
\usepackage{multirow}
%\usepackage{subfig}
\usepackage{paralist}
\usepackage{changepage}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%11022012-START%%%%%%%%%%%%%%
\usepackage[T1]{fontenc} %Useful for file names with underscores in them
\usepackage{float}
\usepackage{grffile}
\newcommand{\hilight}[1]{\colorbox{yellow}{#1}} %To highlight text
\renewcommand{\thefootnote}{\alph{footnote}} %For footnotes
%%%%%%%%%%11022012-STOP%%%%%%%%%%%%%%
-
I don't know whether it helps, but you may try to put the \label inside \caption like this: \caption{When $\lambda = \lambda_{max}$ and M=35.1, Pr=7.20, S=100, G=1/3, rupture takes place at t=1280.0 (within 1\% or\citet{Krishnamoorthy1995a}).\label{k2a}}. Notice that some of the packages are deprecated: epsfig (graphicx is enough), color (use xcolor). As well, I'm not sure whether the packages subfig and sibfigure are not clashing each other. –  tohecz Dec 6 '12 at 13:20
@tohecz Thanks for the tip! Also about the subfig and subfigure intereference... On a side note, would you know how I could label each figure in a minipage... or in a subfigure? –  drN Dec 6 '12 at 13:22
I had no problems compiling your float and \ref{} using your preamble (using MikTeX). I had to comment out \usepackage{mcode} since I did not have that package installed and also your \includegraphics since I do not have the figure. I would actually try to change the name of the graphics so that it is not the same as the the label. I finally renamed one of my eps-files to k2a.eps and your script still works without issues. So I do not think you have anything wrong in the code you have shown. –  Peter Jansson Dec 6 '12 at 13:39
Please, show how your .aux file looks after two compilations. –  tohecz Dec 6 '12 at 13:51
You really should try to make a minimal self contained example that shows the problem (while trying to make that you will probably find out what is causing the problem) Also, unrelated don't use [h] always use at least [htp] if you want to give latex a chance to avoid taking the float to the end of the document. –  David Carlisle Dec 6 '12 at 14:21

As mentioned in the comments, it is very useful to provide a minimum working example (MWE) rather than copying your entire preamble (you did not include the documentclass in your code, but that's important).

For example, the following compiles fine with LaTeX.

\documentclass{article}

\usepackage[T1]{fontenc}

\usepackage{caption}
\captionsetup{margin=10pt,font=small,labelsep=period,labelfont=bf}

\begin{document}

Figure \ref{k2a}.

\begin{figure}[htp]
\centering
%     \includegraphics[width= \columnwidth]{/home/userid/Research/Dissertation/2D/Periodic/k2a}
\caption{When $\lambda = \lambda_{max}$ and M=35.1, Pr=7.20, S=100, G=1/3, rupture takes place at t=1280.0}
\label{k2a}
\end{figure}

\end{document}

Incidentally, your entire preamble compiles fine on my machine with the caption package and the undefinend reference errors only occur because I don't have your citations.

A few other things, mentioned in the comments above and summarised here:

• Load only subfig and not the depreciated subfigure