2

I am trying to create slides with sub-figures that will appear and disappear when the next slide will appear. So far everything looks perfect but my main problem is with sub-figure numbering. When the slides are initialized the numbering starts with (a) which is correct. On the second slide I would expect to see the subfigure as (b) but I see (a) again.

While I was looking online for people having the same problem, I found all this possible solutions:

Beamer + subfigure numbering

Where I tried all solutions:

\setcounter{subfigure}{0}% Reset subfigure counter

\makeatletter
\@addtoreset{subfigure}{framenumber}% subfigure counter resets every frame
\makeatother

\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\AtBeginEnvironment{figure}{\setcounter{subfigure}{0}}% Resets subfigure counter at start of figure environment

Unfortunately this did not work. I searched more and I found also:

Problem with subfigure numbering using ContinuedFloat

Where I tried:

\makeatletter
\newcommand\resetsubfigs{\setcounter{sub\@captype}{0}}
\makeatother

Which is similar to the previous solution, but unfortunately this did not work either.

Does anyone sees something that I am missing? Where I am going so wrong? Working sample of my code is provided under. In order to test the code just use an blank image.

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage[T1]{fontenc}

\makeatletter
\newcommand\resetsubfigs{\setcounter{sub\@captype}{1}}
\makeatother

%\makeatletter
%\newcommand\hyper@makecurrent[1]{}
%\makeatother

\usepackage{float}
\usepackage{caption} %caption for figures
%\usepackage[caption=false]{subfig}
\usepackage{subcaption} %subfigures
\usepackage{graphicx}
\usepackage[english]{babel}
\usepackage[utf8]{inputenc}

\mode<presentation>
\usetheme{Dresden} % so so
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{navigation symbols}{} %take out the navigation symbols
\captionsetup{labelformat=simple}
\usefonttheme[stillsansseriflarge]{structureitalicserif}
\expandafter\def\expandafter\insertshorttitle\expandafter{%
  \insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber}%page numbering

%\makeatletter %reset the numbering on the subfigures (1)
%\@addtoreset{subfigure}{figure} %reset the numbering on the subfigures (2)
%\makeatother %reset the numbering on the subfigures (3)

\title[Title Description] % (optional, only for long titles)
{Main Title}
\subtitle{subtitle}
\vspace*{-2.2em}
\author[Author 1, Author 2]% (optional, for multiple authors)
{Number 1 \and Number 2}
\institute[Institution Here] % (optional)
{
\\
\medskip
{
\emph{author1@email.com}
\emph{author1@email.com}
}
}
\date[2014]{Presentation: 1, 2014}
\subject{Department \LaTeX}

\begin{document}

\begin{frame}[noframenumbering]
 \begin{center}
 % Upper part of the page
 \vspace*{1.0em}
 \includegraphics[width=0.15\textwidth]{image}\\ [0.3cm]    

 \emph{Supervisor:} \\  
  Dr.~First name \\
  \textsc{Last name} 
 \end{center}
 \titlepage
\end{frame}

\section{Section 1} \label{sec:one}

 \subsection{Subsection 1}
 \begin{frame}{Frame Text 1}
  \setbeamercovered{dynamic}%Makes the text appear before it presents nice!!!! 
  \begin{columns}[t] % contents are top vertically aligned
  \begin{column}[T]{5cm} % each column can also be its own environment
    \begin{itemize}
        \item<+-| alert@+> Text column subfigure 1:~\autoref{fig:colsub1}.
        \item<+-| alert@+> Text column subfigure 2:~Figure:~1b.
        \item<+-| alert@+> Text column subfigure 3:~Figure:~1c.
        \item<+-| alert@+> Text column subfigure 4:~Figure:~1d.
      \end{itemize}  
  \end{column}
 \begin{column}[T]{5cm} % alternative top-align that's better for graphics
  \begin{figure}
  \resetsubfigs
    \only<1>{%
    \vspace*{-1.5cm}
      \begin{subfigure}[b]{1.0\linewidth}
        \caption{Column subcation 1} \label{fig:colsub1}
        \hspace*{-1cm}
        \includegraphics[width=7.0cm,height=5cm]{image}
        %\includegraphics[width=\textwidth]{./pdf/core}
        %\includegraphics[height=9.5cm]{./pdf/core}
        \vspace*{-0.6cm}
      \end{subfigure}\hfill
    }
    \only<2>{%
      \vspace*{-1.5cm}
      \begin{subfigure}[b]{1.0\linewidth}
        \caption{Column subcation 2} \label{fig:receiver}
        \hspace*{-0.5cm}
        \includegraphics[width=5.5cm,height=5cm]{image}
      \end{subfigure}
    }
    \only<3>{%
      \vspace*{-1.5cm}
      \begin{subfigure}[b]{1.0\linewidth}
        \caption{Column subcation 3} \protect\label{fig:worst}
        %\hspace*{1cm}
        \vspace*{0.1cm}
        \includegraphics[width=5.5cm,height=5cm]{image}
      \end{subfigure}
    }
    \only<4>{%
      \vspace*{-1.5cm}
      \begin{subfigure}[b]{1.0\linewidth}
        \caption{Column subcation 4} \protect\label{fig:best}
        %\hspace*{0.5cm}
        \vspace*{0.1cm}
        \includegraphics[width=5.5cm,height=5cm]{image}
      \end{subfigure}
    }
  \captionsetup{justification=centering} %Center a two line caption
  \caption{Main Caption for Column subfigures} \protect\label{fig:5}%~\cite{wsn}
   \end{figure}
  \end{column}
 \end{columns}
\end{frame}
\end{document}
  • Not related but please don't use captions in presentations. They serve no purpose. If you really really have to use the slide number. – percusse Nov 16 '14 at 15:50
  • Hello and @percusse and thank you for your time and effort reading my question. I am a bit confused if you mean the captions on the figures or the slide/page number? – Thanos Nov 16 '14 at 16:22
  • @Thanos: References to objects (like citations, sections, figures/tables and even frames) only make sense when the audience can flip back to what you're referring to. So if you call something Figure 1 and Figure 2, but 10 slides later refer back to Figure 1, the audience may very well have no clue what Figure 1 looks like. In those instances it's a good idea to repeat/duplicate the image. As such, there's typically no need to number and reference things explicitly. – Werner Nov 16 '14 at 16:56
  • @Werner: Hello again thank you for your time and effort reading and replying to my question. You are absolutely right about that. The reason that I am enumerating the figures/sub-figures is that I am using references on my bibliography file. Plus I amazed with the ability that I can click on a reference point while I am presenting so I can link the images later on my presentation. Apart from these reasons, I totally agree with you and percusse. – Thanos Nov 16 '14 at 17:13
0

Finally after all of experimentation I found the solution to my problem. I noticed that things get complicated when I use the final \only<4>{}. If I do not use the final \only<4>{} the enumeration continues normally but not the expected output.

So I searched for alternative solutions and I found the \visible{}, with reference to this question:

Beamer: How to show images as step-by-step images

So my final solution is provided in case that someone else might have the same problem. For each picture you might need to play with \vspace*{-1.0} etc. in order to get the desired output.

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}

\usepackage{caption}
\usepackage{subcaption}
\usepackage{cleveref} % autoref

\mode<presentation>
\usetheme{Dresden} % so so
\setbeamertemplate{blocks}[rounded][shadow=true]
\setbeamertemplate{navigation symbols}{} %take out the navigation symbols
\captionsetup{labelformat=simple}
\usefonttheme[stillsansseriflarge]{structureitalicserif}
\expandafter\def\expandafter\insertshorttitle\expandafter{%
  \insertshorttitle\hfill\insertframenumber\,/\,\inserttotalframenumber} %page numbering

\title[Title Description] % (optional, only for long titles){Main Title}
\subtitle{subtitle}
\vspace*{-2.2em}
\author[Author 1, Author 2]% (optional, for multiple authors){Number 1 \and Number 2}
\institute[Institution Here] % (optional)
{
\\
\medskip
{
\emph{author1@email.com}
\emph{author1@email.com}
}
}
\date[2014]{Presentation: 1, 2014}
\subject{Department \LaTeX}

\begin{document}

\begin{frame}[noframenumbering]
  \begin{center}
    % Upper part of the page
    \vspace*{1.0em}
    \includegraphics[width=0.15\textwidth]{image}\\ [0.3cm]    
    \emph{Supervisor:} \\  
      Dr.~First name \\
      \textsc{Last name} 
  \end{center}
 \titlepage
\end{frame}

\section{Section 1} \label{sec:one}
  \subsection{Subsection 1}

\begin{frame}{Frame Text 1}
 \setbeamercovered{dynamic}%Makes the text appear before it presents nice!!!!
  \begin{columns}[t] % contents are top vertically aligned
   \begin{column}[T]{5cm} % each column can also be its own environment
    \begin{itemize}
        \item<+-| alert@+> Text subfigure:~\autoref{fig:a}.
        \item<+-| alert@+> Text subfigure:~\autoref{fig:b}.
        \item<+-| alert@+> Text subfigure:~\autoref{fig:c}.
        \item<+-| alert@+> Text subfigure:~\autoref{fig:d}.
    \end{itemize}  
   \end{column}
  \begin{column}[T]{5cm} % alternative top-align that's better for graphics
   \begin{figure}
    \vspace*{-0.5cm}
     \visible<1-1>{%
      \begin{subfigure}[b]{1.0\linewidth}
       \caption{First subfigure}
       \label{fig:a}
       \includegraphics[width=\linewidth]{image}
      \end{subfigure}\\
     } % Closing visible<1>
    \vspace*{-4.7cm}
     \visible<2-2>{%
      \begin{subfigure}[b]{1.0\linewidth}
       \caption{Second subfigure}
       \label{fig:b}
       \includegraphics[width=\linewidth]{image}
      \end{subfigure}\\
     } % Closing visible<2>
    \vspace*{-4.7cm}
     \visible<3-3>{%
      \begin{subfigure}[b]{1.0\linewidth}
       \caption{Third subfigure}
       \label{fig:c}
       \includegraphics[width=\linewidth]{image}
      \end{subfigure}\\
     } % Closing visible<3>
    \vspace*{-4.7cm}
     \visible<4-4>{
      \begin{subfigure}[b]{1.0\linewidth}
       \caption{Fourth subfigure}
       \label{fig:d}
       \includegraphics[width=\linewidth]{image}
      \end{subfigure}%
     } % Closing visible<4>
    \captionsetup{justification=centering} %Center a two line caption
    \caption{A figure}\label{fig:1}
   \end{figure}
  \end{column}
 \end{columns}
\end{frame}

\end{document}

Sample of output

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.