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

\begin{document}
  \begin{figure}[H]
   \subfloat[Piknik]{\includegraphics[scale=.035,angle=-90]  {images/piknik2.jpg}}      {\label{piknik}}\qquad 
  \subfloat[Oishi]{\includegraphics[scale=.035,angle=-90] {images/oishi2.jpg}}\qquad
  \subfloat[Gardenia]{\includegraphics[scale=.035,angle=-90]{images/gardenia2.jpg}}\qquad
  \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?

1 Answers1

3

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[Piknik\label{piknik}]{\includegraphics[scale=.035,angle=-90]{images/piknik2.jpg}}\qquad 
  \subfloat[Oishi]{\includegraphics[scale=.035,angle=-90] {images/oishi2.jpg}}\qquad
  \subfloat[Gardenia]{\includegraphics[scale=.035,angle=-90]{images/gardenia2.jpg}}
\end{figure}

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

 \end{document}

enter image description here

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.

Gonzalo Medina
  • 505,128