# Problems with Captions and Labels using \Subfloat

I have tried to use the subfig package to insert two photos side by side, and give them different captions, but for some reason this is happening. I would also like to be able to reference the figure from the text, but my labels don't seem to be working.

\begin{figure} [h]
\centering
\subfloat[Figure showing the absorption range of CdSe QDs against Rhodamine 6G, an organic dye[4].]{{\includegraphics[width=6cm]{QDAbsorb} }\label{QDAbsorb}}%
\subfloat[Figure showing the emission profile between CdSe QDs against Rhodamine 6G, an organic dye[4].]{{\includegraphics[width=6cm]{QDFlour}\label{QDFlour}}}%
\caption{2 Figures side by side}%
\label{fig:example}%
\end{figure}


The problem is that the brackets in [4] confuse the parsing of the optional argument of \subfloat. What LaTeX does when it sees the opening bracket [ of an optional argument, is to grab everything up the first closing bracket it sees, which in this case is the one after [4. You can see that is the last part of the caption. Then it grabs the next thing it sees (a period) and uses that for the mandatory argument (what should be the image). The rest of the line (]{\includegraphics...) is just typeset as is, and as the labels are then outside the subfloats altogether, references to them doesn't work.

The solution is simply to place the caption text in a pair of braces i.e. {}.

\documentclass{article}
\usepackage{graphicx}
\usepackage{subfig}

\begin{document}
\ref{QDAbsorb}, \ref{QDFlour}

\begin{figure}
\centering
\subfloat[{Figure showing the absorption range of CdSe QDs against Rhodamine 6G, an organic dye[4].}]{\includegraphics[width=6cm]{QDAbsorb}\label{QDAbsorb}}%