# referencing in subfloat not working

\documentclass[journal]{./IEEE/IEEEtran}
\usepackage{cite,graphicx}
\usepackage{url}
\usepackage{float}
\usepackage{subfig}

\begin{document}
\begin{figure}[H]
\end{figure}

one of the... \ref{piknik} ....
\end{document}


I want to reference an image from the figure to a paragraph using \ref but it is not working. What should I do?

When you process your example document you'll receive several warnings; the second one is something like the following:

Package caption Warning: \label without proper \caption on input line 10.
See the caption package documentation for explanation.


which suggests that you had the \label for the subfigure in the wrong position (in fact, it was outside \subfloat).

The safest place to use \label with \subfloat is either right after the caption inside the first optional argument (as in my example below) or inside the mandatory argument:

\documentclass[journal]{IEEEtran}
\usepackage{cite}
\usepackage[demo]{graphicx}
\usepackage{url}
\usepackage{float}
\usepackage[caption=false]{subfig}

\begin{document}

\begin{figure}[H]
\subfloat[Gardenia]{\includegraphics[scale=.035,angle=-90]{images/gardenia2.jpg}}
\end{figure}

A cross-reference to subfigure~\ref{piknik} ....

\end{document}


Notice that using the caption package with the IEEEtran document class might produce undesired results; you should load the subfig package with the caption=false option, as I did in my example code.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

Of course, restore the original first line to load the class.

• \usepackage[caption=false]{subfig} is the proper way with IEEEtran. – egreg Apr 4 '14 at 9:10