在 beamer 上使用命令 \only{ 时不更改子图编号

在 beamer 上使用命令 \only{ 时不更改子图编号

我正在尝试创建带有子图的幻灯片,这些子图将在下一张幻灯片出现时出现并消失。到目前为止,一切看起来都很完美,但我的主要问题是子图编号。初始化幻灯片时,编号以 (a) 开头,这是正确的。在第二张幻灯片上,我期望看到的子图是 (b),但我再次看到 (a)。

当我在网上寻找遇到同样问题的人时,我发现了所有这些可能的解决方案:

Beamer + 子图编号

我尝试了所有解决方案:

\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

不幸的是,这没有用。我进行了更多搜索,还发现了:

使用 ContinuedFloat 进行子图编号的问题

我尝试过的地方:

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

这与之前的解决方案类似,但不幸的是这也不起作用。

有人发现我遗漏了什么吗?我错在哪里?下面提供了我的代码的工作示例。为了测试代码,只需使用空白图像即可。

\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{[email protected]}
\emph{[email protected]}
}
}
\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}

答案1

经过所有的实验,我终于找到了问题的解决方案。我注意到,当我使用 final 时,事情变得复杂了\only<4>{}。如果我不使用 final,\only<4>{}枚举会正常继续,但不会产生预期的输出。

因此我寻找替代解决方案并找到了\visible{},参考以下问题:

Beamer:如何将图像显示为分步图像

因此,我提供了最终解决方案,以防其他人遇到同样的问题。对于每张图片,你可能需要进行\vspace*{-1.0}一些调整,以获得所需的输出。

\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{[email protected]}
\emph{[email protected]}
}
}
\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}

输出示例

相关内容