2

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} 
\item<+-| alert@+> 1~\autoref{1} 
\item<+-| alert@+> 2~\autoref{2} etc 
\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}
Thanos
  • 1,133
  • 2
  • 10
  • 17
  • 7
    can you please supply us with example code? – codeAndStuff Oct 09 '13 at 15:59
  • 6
    did you run the document at least two times? –  Oct 09 '13 at 16:03
  • 1
    Also kind of mandatory reading : http://tex.stackexchange.com/questions/13625/subcaption-vs-subfig-best-package-for-referencing-a-subfigure – percusse Oct 09 '13 at 18:39
  • Dear all thank you for reply to my question. – Thanos Oct 09 '13 at 23:06
  • Thank you all. \begin{frame} \begin{columns}[t] \begin{column}[T]{5cm} \begin{itemize} \item<+-| alert@+> 1~\autoref{1} \item<+-| alert@+> 2~\autoref{2} etc \end{itemize} \end{column} \begin{column}[T]{5cm} \begin{figure} \only<1>{\begin{subfigure}[b]{1.0\linewidth} \caption{c} \label{1} \includegraphics[width=7.0cm,height=5cm]{fig 1} \end{subfigure} } \only<2>{\begin{subfigure}[b]{1.0\linewidth} \caption{caption 2} \label{2} \includegraphics[width=5.5cm,height=5cm]{fig 2} \end{subfigure} } etc \caption{main} \protect\label{3} \end{figure} \end{column} \end{columns} \end{frame} – Thanos Oct 09 '13 at 23:22
  • I should also mention that I am using this packages:

    \usepackage{hyperref} %\Url Links \usepackage{cleveref} \usepackage{caption} %caption for figures \usepackage{subcaption} %subfigures

    Again thank you in advance for your time and effort replying to my question.

    – Thanos Oct 09 '13 at 23:26
  • @percusse I did read similar documents, this is why I am applying sub captions etc. I can not understand why it only reads one \label and the rest are ignored.

    @Herbert I did run the document twice...but the problem is that it only reads only one \label, the first one, the rest are ignored.

    – Thanos Oct 10 '13 at 09:05
  • @MaxGraves my apologies that the code is not in a readable format but I do not know how to past it in the correct order. Thanks in advance for everybody assistance. – Thanos Oct 10 '13 at 09:09
  • 2
    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 09:52
  • 1
    @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
  • Nothing to do with subfigure: I'll take a look at the beamer code and see if I can understand this a bit more – Joseph Wright Oct 11 '13 at 09:03
  • @JosephWright since subfigure can only see one reference point and miss the rest, you think is a problem with beamer? I appreciate that you spend some time with my problem. – Thanos Oct 12 '13 at 19:20

1 Answers1

2

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} 
\item<+-| alert@+> 1~\ref{1} 
\item<+-| alert@+> 2~\ref{2} etc 
\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}