当我尝试在 beamer 中插入算法时,出现错误“未定义的控制序列。\end{frame}”。
\documentclass{beamer}
\usepackage{etex}
\usetheme{Warsaw}
\setbeamercolor {alerted text} {fg=blue}
\logo{\includegraphics[height=.8cm]{NITlogo}}
\usepackage{beamerthemeshadow}
\usepackage{textcomp}
\usecolortheme[RGB={0,153,0}]{structure}
\usecolortheme{crane}
\useinnertheme{rounded}
\usepackage{graphicx,amsmath}
\usepackage{verbatim,longtable}
\hypersetup{pdfpagemode=FullScreen}
\usepackage{verbatim}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array,colortbl,xcolor}
\usepackage{ragged2e}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{subfig}
\newcommand\Fontvi{\fontsize{6}{7.2}\selectfont}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{frametitle continuation}{}
\usepackage{adjustbox}
\definecolor{deepblue}{RGB}{0,0,128}
\begin{document}
\begin{frame}{}
\begin{algorithm}[H]
\caption{Algorithm }\label{alg:alg1}
\begin{algorithmic}[1]
\STATE Sink node
\STATE Store the value
\subitem a\textunderscore value .
\subitem c\textunderscore value .
\subitem SINR\textunderscore = .
\subitem kappa\textunderscore = .
\STATE Sink node broadcasts
\STATE Each .
\STATE .
\end{algorithmic}
\end{algorithm}
\end{frame}
答案1
添加后\end{document}
,[fragile]
MWE 中的错误消息表明\subitem
未定义。要解决这个问题,请将其定义为执行输出应该执行的操作 - 在下面我使用了
\newcommand{\subitem}{\par\qquad}
但您可以根据需要进行更改。
您的示例中有一些多余的包:您不需要graphicx
或xcolor
使用 beamer,因为 beamer 已经提供了此功能。
\documentclass{beamer}
\usepackage{etex}
\usetheme{Warsaw}
\setbeamercolor {alerted text} {fg=blue}
\logo{\includegraphics[height=.8cm]{example-image}}
\usepackage{beamerthemeshadow}
\usepackage{textcomp}
\usecolortheme[RGB={0,153,0}]{structure}
\usecolortheme{crane}
\useinnertheme{rounded}
%\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{verbatim,longtable}
\hypersetup{pdfpagemode=FullScreen}
\usepackage{verbatim}
\usepackage{pdflscape}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{array,colortbl}
%\usepackage{xcolor}
\usepackage{ragged2e}
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{subfig}
\newcommand\Fontvi{\fontsize{6}{7.2}\selectfont}
\setbeamertemplate{caption}[numbered]
\setbeamertemplate{frametitle continuation}{}
\usepackage{adjustbox}
\definecolor{deepblue}{RGB}{0,0,128}
\newcommand{\subitem}{\par\qquad}
\begin{document}
\begin{frame}[fragile]
\begin{algorithm}[H]
\caption{Algorithm }\label{alg:alg1}
\begin{algorithmic}[1]
\STATE Sink node
\STATE Store the value
\subitem a\textunderscore value .
\subitem c\textunderscore value .
\subitem SINR\textunderscore = .
\subitem kappa\textunderscore = .
\STATE Sink node broadcasts
\STATE Each .
\STATE .
\end{algorithmic}
\end{algorithm}
\end{frame}
\end{document}