# \usepackage{caption} breaks references to tables

I'm formatting the listings captions as follows:

\usepackage{caption}
\DeclareCaptionFont{white}{\color{white}}
\DeclareCaptionFormat{listing}{\colorbox{gray}{\parbox{\textwidth}{#1#2#3}}}
\captionsetup[lstlisting]{format=listing,labelfont=white,textfont=white}

However, I realized that just writting \usepackage{caption} breaks references to tables, causing warnings like:

LaTeX Warning: Reference `table:swtp' on page 13 undefined on input line 44.

and LaTeX writes "Table. ??" in the generated document.

This an example that gives me the problem:

\documentclass[10pt,letterpaper]{report}
\usepackage{caption}
\begin{document}

\chapter{Chapter}

See the Table ~\ref{table:example}

\begin{table}[htdp]
\begin{center}
\begin{tabular}{ | c | c |}
\hline
A & B  \\ \hline
1 & 2 \\
\hline
\end{tabular}
\caption{my cap}
\end{center}
\label{table:example}
\end{table}

\end{document}
-
Please provide a complete MWE that shows your problem. Do you compile twice? –  Marco Daniel Apr 29 '12 at 16:49
If you don't know what a MWE is you can read it here: minimal working example (MWE) –  Marco Daniel Apr 29 '12 at 17:20
You forgot to mention the warning Package caption Warning: \label without proper \caption on input line 19. See the caption package documentation for explanation. your example causes. When taking a look at the caption package doc you'll see that's not a bug, it's a feature ;-) –  Axel Sommerfeldt Apr 29 '12 at 19:28

With

\begin{table}[htdp]
\begin{center}
\begin{tabular}{ | c | c |}
\hline
A & B  \\ \hline
1 & 2 \\
\hline
\end{tabular}
\caption{my cap}
\end{center}
\label{table:example}
\end{table}

the label is defined when the center environment has already been closed and the object which the reference should be attached to has been forgotten.

Never use the center environment inside figure or table:

\begin{table}[htbp]
\centering
\begin{tabular}{ | c | c |}
\hline
A & B  \\ \hline
1 & 2 \\
\hline
\end{tabular}
\caption{my cap}\label{table:example}
\end{table}

Notice also that d is not among the possible float specifiers and probably you were meaning b (bottom).

-