3

I'm trying to reference the subfloat using \ref{img1} and \ref{img2} but its not working, a ? keeps appearing in the reference location. If anyone could please advise.

\begin{figure}[t]
\subfloat[]{\includegraphics[width=.49\linewidth]{img1}}\label{img1}
\subfloat[]{\includegraphics[width=.49\linewidth]{img2}}\label{img2}
\caption{The two methods a and b.} 
\label{fig:KC3}
\end{figure}
Tak
  • 2,346
  • 4
  • 20
  • 33

2 Answers2

2

Put the \labels inside the brackets meant for sub captions like

\subfloat[\label{img1}]{....

Code:

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{subfig}
\begin{document}
  \begin{figure}[t]
\subfloat[\label{img1}]{\includegraphics[width=.49\linewidth]{img1}}
\subfloat[\label{img2}]{\includegraphics[width=.49\linewidth]{img2}}
\caption{The two methods a and b.}
\label{fig:KC3}
\end{figure}
This is \ref{img1} and \ref{img2} but its not working
\end{document}

enter image description here

0

When a label is declared within a float environment, the \ref{...} will return the respective fig/table number, but it must occur after the caption. Wikipedia reference

I have never used subfloat before, but I had the same problem with figure and subfigure. This should fix it ;)

Second, I did some small research on subfloats and there are some strong disagreements to used it. I know subfloat is not your problem right now, but maybe good to look at how you could implemented it with other methods link