# Can't label an image in subfigure

I have been trying to label images in subfigures and then reference them in the caption of the main figure environment. But I get error "Label without proper reference" and "reference undefined error" for all the three subfigures. Can anyone find out the problem?

\begin{figure}[t]
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img1}
\label{fig:original}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img2}
\label{fig:smooth}
\end{subfigure}
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img3}
\label{fig:binarySkeleton}
\end{subfigure}
\caption{\ref{fig:original}Image 1 \ref{fig:smooth}image 2 \ref{fig:binarySkeleton} Image 3 }
\label{fig:pre-processing}
\end{figure}

• Welcome to TeX.SX! Please, complete the example to a full document. Which package/definition is used for environment subfigure? – Heiko Oberdiek Nov 5 '16 at 21:07

If you have images/plots that has labels a, b, c in them, and you don't need captions, then you can use {\phantomsubcaption\label{subfiglabel}}. For example:

\documentclass[a4paper]{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\includegraphics[width=0.3\linewidth]{example-image-a}\hfill
\includegraphics[width=0.3\linewidth]{example-image-b}\hfill
\includegraphics[width=0.3\linewidth]{example-image-c}
{\phantomsubcaption\label{first subfig}}
{\phantomsubcaption\label{second subfig}}
{\phantomsubcaption\label{third subfig}}
\caption{...}
\label{full fig}
\end{figure}

See fig.~\ref{full fig}, which contains \ref{first subfig}, \ref{second subfig} and \ref{third subfig}.
\end{document}


\documentclass[demo]{article}
\usepackage{subcaption, graphicx}

\begin{document}

\begin{figure}[t]
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img1}
\caption{}\label{fig:original}
\end{subfigure}
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img2}
\caption{}\label{fig:smooth}
\end{subfigure}
\hfill
\begin{subfigure}{0.3\linewidth}
\includegraphics[width=\linewidth]{./Figures/img3}
\caption{}\label{fig:binarySkeleton}
\end{subfigure}
\caption{\ref{fig:original} Image 1, \ref{fig:smooth} image 2, \ref{fig:binarySkeleton} Image 3.}%
\label{fig:pre-processing}
\end{figure}

\end{document}


• it did work but now I have the labels (a), (b),.. which I don't want ! is there any way around? – Hemant Kumar Nov 5 '16 at 21:13
• Welcome! How do you want to reference something that is not associated to the value of a counter? You may change the way the counter displays, but a counter is required. – Bernard Nov 5 '16 at 21:16