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}
12
  • 7
    can you please supply us with example code? Commented Oct 9, 2013 at 15:59
  • 6
    did you run the document at least two times?
    – user2478
    Commented Oct 9, 2013 at 16:03
  • 1
    Also kind of mandatory reading : tex.stackexchange.com/questions/13625/…
    – percusse
    Commented Oct 9, 2013 at 18:39
  • 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
    Commented Oct 10, 2013 at 9: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
    Commented Oct 10, 2013 at 10:16

1 Answer 1

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}
3
  • 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
    Commented Feb 9, 2018 at 22:19
  • 1
    @Thanos I just fixed a little bug, please see my updated code. Commented Feb 9, 2018 at 22:26
  • works perfectly. Thanks for all of your effort.
    – Thanos
    Commented Mar 21, 2018 at 17:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .