我必须在 latex 中编写一个很长的伪代码,但一张幻灯片只占用 22 个语法。如何在下一张幻灯片中继续剩余的语法。
请查看我的代码,我正在使用额外的包来存放其他文档。
提前致谢!
\documentclass{beamer}
\usepackage{amssymb}
\addtobeamertemplate{navigation symbols}{}{ \usebeamerfont{footline}
\usebeamercolor[fg]{footline} \hspace{1em} } \setbeamertemplate{footline}{
\raisebox{5pt}{\makebox[\paperwidth]{\hfill\makebox[10pt]
{\scriptsize\insertframenumber}}}} \renewcommand\thefootnote{\textcolor{red}
{\arabic{footnote}}} \usepackage[multiple]{footmisc} \usepackage[usestackEOL]
{stackengine} \usepackage{scalerel}
\def\myoverline#1{\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}
\stackengine{1.2\LMpt}{$\SavedStyle#1$}{\rule{\wd0}{0.95\LMpt}}{O}{c}{F}{F}{S}}}
\renewcommand{\footnotesize}{\fontsize{7pt}{9pt}\selectfont}
\usepackage{algpseudocode}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
\usepackage{xcolor}
\usepackage{lmodern}
\usepackage[english]{babel}
\usepackage[utf8x]{inputenc}
\usepackage{graphicx}
\usepackage{color}
\setbeamercolor{frametitle}{fg=blue}
\usepackage{amsthm}
\setbeamertemplate{theorems}[numbered]
\newtheorem{proposition}[theorem]{Proposition} \theoremstyle{definition}
\newtheorem*{sketch}{Proof sketch.}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{amsmath, latexsym}
\usepackage{amssymb}
\usepackage{mathtools}
\usepackage{amsthm}
\usepackage{amsmath,amsfonts}
\usepackage{amssymb}
\usepackage{multirow}
\usepackage{graphicx}
\usepackage{graphicx}
\begin{document}
\begin{frame}{Main Results} \begin{algorithm} [H] \tiny
\caption{Determine whether a given vector is quasi-uniform entropy vector and if it is, give a consistent quasi-uniform distribution.}\label{alg:1} \begin{algorithmic}[1]
\Require $\mathbf{h}^{\text{t}}$
\Ensure $\mathbf{h}^{\text{t}}, \mathbf{p}$
\State {$\mathnormal{s}{\alpha} \leftarrow 2^{\textbf{h}{\alpha}^{\text{t}}}, \alpha \subseteq [\mathnormal{n}]$}
\If {$\mathnormal{s}_{\alpha} \in \mathbb{N}, \emptyset \neq \alpha \subseteq [\mathnormal{n}]$}
\State {$\mathnormal{S}{\mathnormal{k}} \leftarrow {0,1, \ldots,\mathnormal{s}{\mathnormal{k}}-1}$}
\State {$\mathcal{X}{[\mathnormal{n}]} \leftarrow \prod{\mathnormal{k}=1}^{\mathnormal{n}}\mathnormal{S}_{\mathnormal{k}}$}
\Else \\\
\Return {$\textbf{h}^{\text{t}} \notin \Lambda_{\mathnormal{n}}$ \text{and terminate}}
\EndIf
\State{$\mathnormal{i} \leftarrow 1, \mathbf{p} \leftarrow \mathbf{0}{|\mathcal{X}{[\mathnormal{n}]}|\times 1}, \mathnormal{m} \leftarrow |\mathcal{X}_{[\mathnormal{n}]}|, \mathnormal{f} \leftarrow 0$}
\State \textbf{function} {M{\tiny AKE}QUD $(\mathnormal{i},\mathnormal{s}{[\mathnormal{n}]},\mathnormal{m},\mathbf{p},\textbf{h}^{\text{t}},\mathcal{X}{[\mathnormal{n}]},\mathnormal{f})$}
\If{$\mathnormal{m}=1$}
\State {$\mathnormal{p}(\mathcal{X}{[n]}) \leftarrow 1- \sum{\mathnormal{x}=1}^{\mathcal{X}_{[\mathnormal{n}]}-1}\mathnormal{p}(\mathnormal{x})$}
\State{$\mathbf{p'}\leftarrow \textbf{p}, \mathbf{h'}\leftarrow \textbf{h}$}
\If{$\mathnormal{p}(\boldsymbol{\mathnormal{x}}{\alpha}) \in {0, 1/\mathnormal{s}{\alpha}}, \forall \boldsymbol{\mathnormal{x}}{\alpha} \in \boldsymbol{\mathcal{X}}{\alpha}, \sum_{\boldsymbol{\mathnormal{x}}{\alpha}}\mathnormal{p}(\boldsymbol{\mathnormal{x}}{\alpha})=1, \forall \emptyset \neq \alpha \subsetneq [\mathnormal{n}]$}
\State {$\mathnormal{f} \leftarrow 1$}
\EndIf
\Else
\State{$\mathnormal{v} \leftarrow \left[0, \frac{1}{\mathnormal{s}_{[\mathnormal{n}]}}\right]$}
\For {$\mathnormal{j}=1:1:2$}
\If {$\mathnormal{f}=1$} \\\
\Return {$\mathbf{h}^{\text{t}} \in \Lambda_{\mathnormal{n}}$ \text{and terminate}}
\EndIf
\State $\mathnormal{p}(\mathnormal{i}) \leftarrow \mathnormal{v}(\mathnormal{j})$
\If {$0 \leq 1-\sum_{a=1}^{|\mathcal{X}{[\mathnormal{n}]}|}\mathnormal{p}(a) \leq \frac{|\mathcal{X}{[\mathnormal{n}]}|-i}{\mathnormal{s}{[\mathnormal{n}]}}, \text{Pr}{\boldsymbol{\mathnormal{X}}{\alpha} = \boldsymbol{\mathnormal{x}}{\alpha}} \leq \frac{1}{\mathnormal{s}{\alpha}},\forall \boldsymbol{\mathnormal{x}}{\alpha} \in \boldsymbol{\mathcal{X}}{\alpha},\forall \emptyset \neq \alpha \subsetneq [\mathnormal{n}]$} \
\Return {M{\tiny AKE}QUD$(\mathnormal{i}+1,\mathnormal{s}{[\mathnormal{n}]},\mathnormal{m}-1,\mathbf{p},\mathbf{h}^{\text{t}},\mathcal{X}{[\mathnormal{n}]},\mathnormal{f})$}
\EndIf
\EndFor
\EndIf
\State \textbf{end function}\
\Return {$\mathbf{h}^{\text{t}} \notin \Lambda_{\mathnormal{n}}$} \end{algorithmic} \end{algorithm} \end{frame}
\end{document}
答案1
如果你避免将你的算法包装到浮动环境中(这不是很有用,因为 beamer 没有浮动机制),你可以让 beamer 使用框架选项自动拆分你的算法allowframebreaks
:
\documentclass{beamer}
%\usepackage{amssymb}
\addtobeamertemplate{navigation symbols}{}{ \usebeamerfont{footline}
\usebeamercolor[fg]{footline} \hspace{1em} } \setbeamertemplate{footline}{
\raisebox{5pt}{\makebox[\paperwidth]{\hfill\makebox[10pt]
{\scriptsize\insertframenumber}}}} \renewcommand\thefootnote{\textcolor{red}
{\arabic{footnote}}}
%\usepackage[multiple]{footmisc}
\usepackage[usestackEOL]{stackengine}
\usepackage{scalerel}
\def\myoverline#1{\ThisStyle{\setbox0=\hbox{$\SavedStyle#1$}
\stackengine{1.2\LMpt}{$\SavedStyle#1$}{\rule{\wd0}{0.95\LMpt}}{O}{c}{F}{F}{S}}}
\renewcommand{\footnotesize}{\fontsize{7pt}{9pt}\selectfont}
\usepackage{algpseudocode}
\usepackage{ragged2e}
\usepackage{lipsum}
\usepackage[T1]{fontenc}
%\usepackage{xcolor}
\usepackage{lmodern}
\usepackage[english]{babel}
%\usepackage[utf8x]{inputenc}
%\usepackage{graphicx}
%\usepackage{color}
\setbeamercolor{frametitle}{fg=blue}
%\usepackage{amsthm}
\setbeamertemplate{theorems}[numbered]
\newtheorem{proposition}[theorem]{Proposition} \theoremstyle{definition}
\newtheorem*{sketch}{Proof sketch.}
\usepackage{algorithm}
\usepackage{algpseudocode}
%\usepackage{amsmath}
\usepackage{latexsym}
%\usepackage{amssymb}
\usepackage{mathtools}
%\usepackage{amsthm}
%\usepackage{amsmath,amsfonts}
%\usepackage{amssymb}
\usepackage{multirow}
%\usepackage{graphicx}
%\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\begin{frame}[allowframebreaks]
\frametitle{Main Results}
\captionof{algorithm}{Determine whether a given vector is quasi-uniform entropy vector and if it is, give a consistent quasi-uniform distribution.}
\label{alg:1}
\tiny
\begin{algorithmic}[1]
\Require $\mathbf{h}^{\text{t}}$
\Ensure $\mathbf{h}^{\text{t}}, \mathbf{p}$
\State {$\mathnormal{s}{\alpha} \leftarrow 2^{\textbf{h}{\alpha}^{\text{t}}}, \alpha \subseteq [\mathnormal{n}]$}
\If {$\mathnormal{s}_{\alpha} \in \mathbb{N}, \emptyset \neq \alpha \subseteq [\mathnormal{n}]$}
\State {$\mathnormal{S}{\mathnormal{k}} \leftarrow {0,1, \ldots,\mathnormal{s}{\mathnormal{k}}-1}$}
\State {$\mathcal{X}{[\mathnormal{n}]} \leftarrow \prod{\mathnormal{k}=1}^{\mathnormal{n}}\mathnormal{S}_{\mathnormal{k}}$}
\Else \\\
\Return {$\textbf{h}^{\text{t}} \notin \Lambda_{\mathnormal{n}}$ \text{and terminate}}
\EndIf
\State{$\mathnormal{i} \leftarrow 1, \mathbf{p} \leftarrow \mathbf{0}{|\mathcal{X}{[\mathnormal{n}]}|\times 1}, \mathnormal{m} \leftarrow |\mathcal{X}_{[\mathnormal{n}]}|, \mathnormal{f} \leftarrow 0$}
\State \textbf{function} {M{\tiny AKE}QUD $(\mathnormal{i},\mathnormal{s}{[\mathnormal{n}]},\mathnormal{m},\mathbf{p},\textbf{h}^{\text{t}},\mathcal{X}{[\mathnormal{n}]},\mathnormal{f})$}
\If{$\mathnormal{m}=1$}
\State {$\mathnormal{p}(\mathcal{X}{[n]}) \leftarrow 1- \sum{\mathnormal{x}=1}^{\mathcal{X}_{[\mathnormal{n}]}-1}\mathnormal{p}(\mathnormal{x})$}
\State{$\mathbf{p'}\leftarrow \textbf{p}, \mathbf{h'}\leftarrow \textbf{h}$}
\If{$\mathnormal{p}(\boldsymbol{\mathnormal{x}}{\alpha}) \in {0, 1/\mathnormal{s}{\alpha}}, \forall \boldsymbol{\mathnormal{x}}{\alpha} \in \boldsymbol{\mathcal{X}}{\alpha}, \sum_{\boldsymbol{\mathnormal{x}}{\alpha}}\mathnormal{p}(\boldsymbol{\mathnormal{x}}{\alpha})=1, \forall \emptyset \neq \alpha \subsetneq [\mathnormal{n}]$}
\State {$\mathnormal{f} \leftarrow 1$}
\EndIf
\Else
\State{$\mathnormal{v} \leftarrow \left[0, \frac{1}{\mathnormal{s}_{[\mathnormal{n}]}}\right]$}
\For {$\mathnormal{j}=1:1:2$}
\If {$\mathnormal{f}=1$} \\\
\Return {$\mathbf{h}^{\text{t}} \in \Lambda_{\mathnormal{n}}$ \text{and terminate}}
\EndIf
\State $\mathnormal{p}(\mathnormal{i}) \leftarrow \mathnormal{v}(\mathnormal{j})$
\If {$0 \leq 1-\sum_{a=1}^{|\mathcal{X}{[\mathnormal{n}]}|}\mathnormal{p}(a) \leq \frac{|\mathcal{X}{[\mathnormal{n}]}|-i}{\mathnormal{s}{[\mathnormal{n}]}}, \text{Pr}{\boldsymbol{\mathnormal{X}}{\alpha} = \boldsymbol{\mathnormal{x}}{\alpha}} \leq \frac{1}{\mathnormal{s}{\alpha}},\forall \boldsymbol{\mathnormal{x}}{\alpha} \in \boldsymbol{\mathcal{X}}{\alpha},\forall \emptyset \neq \alpha \subsetneq [\mathnormal{n}]$} \
\Return {M{\tiny AKE}QUD$(\mathnormal{i}+1,\mathnormal{s}{[\mathnormal{n}]},\mathnormal{m}-1,\mathbf{p},\mathbf{h}^{\text{t}},\mathcal{X}{[\mathnormal{n}]},\mathnormal{f})$}
\EndIf
\EndFor
\EndIf
\State \textbf{end function}\
\Return {$\mathbf{h}^{\text{t}} \notin \Lambda_{\mathnormal{n}}$} \end{algorithmic}
\end{frame}
\end{document}
无关:
- 不要多次加载同一个包
- 你不需要加载任何这些
ams*
包,beamer 会自动加载它们 - 不要
footmisc
与 beamer 一起使用,它会使脚注消失 - 您不需要加载
xcolor
,color
beamer 会自动加载它们 - 最好不要使用该
utf8x
选项。如果你的 latex 发行版比较新,utf8
则会自动使用 - 不需要
graphicx
,beamer 会自动加载