在 beamer 中使用 \only 命令时出现问题

在 beamer 中使用 \only 命令时出现问题

我在 beamer 中创建了以下框架:

\begin{frame}[t]{Adjacency Matrix}
    \vspace{1em}
    \only<1>{
    \begin{block}{What is an adjacency matrix?}
    \vspace{0.5em}
     An adjacency matrix is a square matrix used to represent a finite graph.
    \end{block}
    \vspace{0.5em}
    For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
    \\\vspace{1em}
    If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
    }

   % ........

\end{frame}

现在,在这个框架内,我想要几张幻灯片。为此,我编写了以下代码:

\setbeamertemplate{itemize items}[ball]
        \begin{enumerate}
        \only<2>{
            \item Unweighted Graph
                \vspace{1em}
                \begin{itemize}
                    \item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
                \end{itemize}

                \[      \Scale[1]{
                        V_{i,j} = \begin{cases}
                                    1 & if ~ edge(i,j) ~ exists \\
                                    0 & otherwise
                                \end{cases}
                        }
                \]
            }
            \only<3>{
            \item Weighted Graph
                \begin{itemize}
                    \item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge. 
                \end{itemize}
            }
        \end{enumerate}

我希望第一项(未加权图表,枚举 1)显示在第 2 张幻灯片上,第二项(加权图表,枚举 2)显示在幻灯片 3 上。但是当我在 sharelatex 上运行此程序时,它显示以下错误:

 main.tex, line 106
LaTeX Error: Something's wrong--perhaps a missing \item.

There are no entries found in a list you have created. Make sure you label list entries using the \item command, and that you have not used a list inside a table.

 Learn more Was this hint helpful? Yes / No
See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.106 \end{frame}

Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

目前它看起来是这样的:

在此处输入图片描述

在此处输入图片描述

无加权图和加权图均枚举1。

我究竟做错了什么?

完整代码:

\documentclass[12pt]{beamer}
\usetheme{metropolis}
\usecolortheme{spruce}

\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{graphicx}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%

% Swap the definition of \abs* and \norm*, so that \abs
% and \norm resizes the size of the brackets, and the 
% starred version does not.
\makeatletter
\let\oldabs\abs
\def\abs{\@ifstar{\oldabs}{\oldabs*}}
%
\let\oldnorm\norm
\def\norm{\@ifstar{\oldnorm}{\oldnorm*}}
\makeatother


\title[About Beamer]{Graph Representation Techniques}
\author[Author A and Author B]{Tanjim Bin Faruk (1505082) \\ Tanjim Munir (1505083) }
\institute{}
\date{\today}

\setbeamertemplate{title page}{
  \begin{minipage}[b][\paperheight]{\textwidth}
    \ifx\inserttitlegraphic\@empty\else\usebeamertemplate*{title graphic}\fi
    \vfill%
    \centering % NEW
    \ifx\inserttitle\@empty\else\usebeamertemplate*{title}\fi
    \ifx\insertsubtitle\@empty\else\usebeamertemplate*{subtitle}\fi
    \usebeamertemplate*{title separator}
    \vspace*{10mm}
    \ifx\beamer@shortauthor\@empty\else\usebeamertemplate*{author}\fi
    \vspace*{20mm} % NEW
    \ifx\insertdate\@empty\else\usebeamertemplate*{date}\fi
    \ifx\insertinstitute\@empty\else\usebeamertemplate*{institute}\fi
    \vfill
    \vspace*{1mm}
  \end{minipage}
}

\setbeamertemplate{title}{
%  \raggedright%
    \centering
  \linespread{1.0}%
  \inserttitle%
  \par%
  \vspace*{0.5em}
}


\begin{document}
\metroset{block = fill}

\begin{frame}
\titlepage
\end{frame}

\begin{frame}[t]{Adjacency Matrix}
    \vspace{1em}
    \only<1>{
    \begin{block}{What is an adjacency matrix?}
    \vspace{0.5em}
     An adjacency matrix is a square matrix used to represent a finite graph.
    \end{block}
    \vspace{0.5em}
    For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
    \\\vspace{1em}
    If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
    }

    \setbeamertemplate{itemize items}[ball]
        \begin{enumerate}
        \only<2>{
            \item Unweighted Graph
                \vspace{1em}
                \begin{itemize}
                    \item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
                \end{itemize}

                \[      \Scale[1]{
                        V_{i,j} = \begin{cases}
                                    1 & if ~ edge(i,j) ~ exists \\
                                    0 & otherwise
                                \end{cases}
                        }
                \]
            }
            \only<3>{
            \item Weighted Graph
                \begin{itemize}
                    \item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge. 
                \end{itemize}
            }
        \end{enumerate}

\end{frame}

\end{document}

答案1

您的代码存在的问题是,在第一个覆盖层上\begin{enumerate}...\end{enumerate}已经存在,但没有单个项目 - 这是不允许的。

所以你必须确保第一帧上没有空的枚举。

\documentclass[12pt]{beamer}
\usetheme{moloch}% modern fork of the metropolis theme
\usecolortheme{spruce}

\usepackage{mathtools}
\usepackage{amsmath}
\usepackage{fixmath}
\usepackage{graphicx}

\newcommand*{\Scale}[2][4]{\scalebox{#1}{$#2$}}%
\newcommand*{\Resize}[2]{\resizebox{#1}{!}{$#2$}}%

\DeclarePairedDelimiter\abs{\lvert}{\rvert}%
\DeclarePairedDelimiter\norm{\lVert}{\rVert}%


\begin{document}

\begin{frame}[t]{Adjacency Matrix}
    \vspace{1em}
    \only<1>{
    \begin{block}{What is an adjacency matrix?}
    \vspace{0.5em}
     An adjacency matrix is a square matrix used to represent a finite graph.
    \end{block}
    \vspace{0.5em}
    For a graph with $\mathbold{\abs{V}}$ vertices, an adjacency matrix is a $\mathbold{\abs{V} \times \abs{V}}$ matrix.
    \\\vspace{1em}
    If the edge between vertex $\mathbold{i}$ and vertex $\mathbold{j}$ is denoted by $\mathbold{V_{i,j}}$ then there are two possibilities.
    }

        \only<2-3>{
    \setbeamertemplate{itemize items}[ball]
        \begin{enumerate}
        \only<2>{
            \item Unweighted Graph
                \vspace{1em}
                \begin{itemize}
                    \item Matrix of 0s and 1s where in row $\mathbold{i}$ and column $\mathbold{j}$ is $1$ iff the edge $\mathbold{(i,j)}$ is in the graph
                \end{itemize}

                \[      \Scale[1]{
                        V_{i,j} = \begin{cases}
                                    1 & if ~ edge(i,j) ~ exists \\
                                    0 & otherwise
                                \end{cases}
                        }
                \]
            }
            \addtocounter{enumi}{1}
            \only<3>{
            \item Weighted Graph
                \begin{itemize}
                    \item Edge weight is placed in $\mathbold{V_{i,j}}$ entry if there is an edge and a special value (perhaps \textit{null} to indicate absence of an edge. 
                \end{itemize}
            }
        \end{enumerate}
            }

\end{frame}

\end{document}

相关内容