# Multiple \label commands before \ref

I have tried several approaches to solve my problem but unfortunately none successful yet. I can not find documentation mentioning how to solve this particular case. My problem is that I am using a subfigure in beamer and I am trying to create multiple \ref points before the \label appear in the same figure. When compiling the .tex document only one reference point appears and the rest are appearing as ??. Is there any possible solution to my problem?

EDIT: The code I'm using

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[english]{babel}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{caption}
\usepackage{subcaption}

\mode<presentation>
\setbeamertemplate{caption}[numbered]

\begin{document}
\begin{frame}
\begin{columns}[t]
\begin{column}[T]{5cm}
\begin{itemize}
\end{itemize}
\end{column}
\begin{column}[T]{5cm}
\begin{figure}
\only<1>{\begin{subfigure}[b]{1.0\linewidth}
\caption{sub caption 1}
\label{1}
\includegraphics[width=7.0cm,height=5cm]{fig 1}
\end{subfigure} }
\only<2>{\begin{subfigure}[b]{1.0\linewidth}
\caption{sub caption 2}
\label{2}
\includegraphics[width=5.5cm,height=5cm]{fig 2}
\end{subfigure} }
\caption{main}
\protect\label{3}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\end{document}

• can you please supply us with example code? – codeAndStuff Oct 9 '13 at 15:59
• did you run the document at least two times? – user2478 Oct 9 '13 at 16:03
• Also kind of mandatory reading : tex.stackexchange.com/questions/13625/… – percusse Oct 9 '13 at 18:39
• I've added your code into your question. Please check it further and complete it such that it starts with \documentclass and up to \end{document} with the necessary packages to replicate the problem. You can use the edit button under the question to add the details. – percusse Oct 10 '13 at 9:52
• @percusse Thank you for your assistance. I have just added all necessary packets and I tested the code on my system it compiles and executes. Unfortunately only the first figure it appears as 1a the second produces ??. Thank you again for your time and effort. – Thanos Oct 10 '13 at 10:16

The problem is that if you only show one subfigure per slide the counter of both subfigures is a which leads to problem with the labels. As a workaround to this problem, you can make the subcaption invisible instead and introduce an additional phantom caption:

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[english]{babel}
%\usepackage{cleveref}
\usepackage{caption}
\usepackage{subcaption}

\mode<presentation>
\setbeamertemplate{caption}[numbered]

\begin{document}
\begin{frame}
\begin{columns}[t]
\begin{column}[T]{5cm}
\begin{itemize}
\end{itemize}
\end{column}
\begin{column}[T]{5cm}
\begin{figure}%
\only<1>{%
\begin{subfigure}[b]{\linewidth}%
\caption{sub caption 1}\label{1}%
\includegraphics<1>[width=3cm]{example-image-a}%
\end{subfigure}%
}%
\only<2>{{\phantomsubcaption}}%
\visible<2>{%
\begin{subfigure}[b]{\linewidth}%
\caption{sub caption 2}\label{2}%
\includegraphics<2>[width=3cm]{example-image-b}%
\end{subfigure}%
}
\caption{main}
\label{3}
\end{figure}
\end{column}
\end{columns}
\end{frame}
\end{document}

• Hello @samcarter I will compile it and test it. The idea sounds great. Thank you for your time and effort reading and approaching my problem. – Thanos Feb 9 '18 at 22:19
• @Thanos I just fixed a little bug, please see my updated code. – samcarter_is_at_topanswers.xyz Feb 9 '18 at 22:26
• works perfectly. Thanks for all of your effort. – Thanos Mar 21 '18 at 17:25