将长算法融入投影仪演示中

将长算法融入投影仪演示中

我想在 beamer 框架中包含以下算法。我的 MWE 如下所示

\documentclass[11pt]{beamer}% http://ctan.org/pkg/beamer
\mode<presentation>

\usetheme{Madrid}

\usepackage{float}
\usepackage{adjustbox}

\usepackage{algpseudocode,algorithm,algorithmicx}
\setbeamertemplate{frametitle}[default][center]

\usepackage{xkeyval}

\usepackage{etoolbox}
\usepackage{ragged2e}
\apptocmd{\frame}{}{\justifying}{} % Allow optional arguments after frame.

\hypersetup{colorlinks=true,allcolors=blue}

\setbeamertemplate{caption}[numbered]

\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry location}{}
\setbeamertemplate{bibliography entry note}{}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{epstopdf}

\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}
%\framesubtitle{\centerline{frame subtitle}}

\begin{algorithm}[H]
    \caption{Pseudocode for the GWO}
    \label{gwo}
    \begin{algorithmic}[1]
        %   \Procedure{Hybrid BAT-Genetic Algorithm}{}
        \\Input :Grey wolf population:$X_{i}(i = 1, 2, ..., n)$,Maximum Number of iteration:Max\_it
        \\Output :$X_{a}$ : Optimal Position(Optimized filter coefficients)
        \\Objective function : PSNR
        \hrule
        \\Initialize the Grey wolf population $X_{i} = (i=1,2, ...,n)$
        \\Initialize the coefficient vectors a, A, and C
        \State $\vec{A}=2\vec{a}\vec{r_1}-\vec{a}$
        \State $\vec{C}=2\vec{r_2}$
        \Comment where components of are linearly decreased from 2 to 0 over the course of iterations and,\\ are random vectors in $[0,1]$
        \For{all $X_{i}$}
        \State Calculate fitness $F(X_{i})$ of all $X_{i}$
        \EndFor
        \State Rank the gray wolf in descending order based on the fitness
        \State $X_{\alpha}$ = the first search agent
        \State $X_{\beta}$ = the second search agent
        \State $X_{\delta}$ = the third search agent 
        \State t=1;
        \While{t\textless Max\_it}
        \For{i=1:n}
        \State Update the position of the current search agent $\vec{F}(t+1) = \frac{\vec{F_{1}}+\vec{F_{2}}+\vec{F_{3}}}{3}$
        \EndFor
        \State Update $a$,$A$, and $C$
        \For{all $X_{i}$}
        \State Calculate fitness $F(X_{i})$ of all $X_{i}$
        \EndFor
        \State Update $X_{\alpha}$, $X_{\beta}$, and $X_{\delta}$
        \State t=t+1;
        \EndWhile
        \State Return the first best agent $X_{\alpha}$ found so far
        \\Post-processing the results and visualization
        %   \EndProcedure
    \end{algorithmic}
\end{algorithm}

\end{frame}
\end{document}

答案1

我把你的算法分成两个框架......

以下是代码:

\documentclass[11pt]{beamer}% http://ctan.org/pkg/beamer
\mode<presentation>

\usetheme{Madrid}

\usepackage{float}
\usepackage{adjustbox}

\usepackage{algpseudocode,algorithm,algorithmicx}
\usepackage{algcompatible}
\setbeamertemplate{frametitle}[default][center]

\usepackage{caption}

\usepackage{xkeyval}

\usepackage{etoolbox}
\usepackage{ragged2e}
\apptocmd{\frame}{}{\justifying}{} % Allow optional arguments after frame.

\hypersetup{colorlinks=true,allcolors=blue}

\setbeamertemplate{caption}[numbered]

\setbeamertemplate{bibliography entry title}{}
\setbeamertemplate{bibliography entry location}{}
\setbeamertemplate{bibliography entry note}{}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{epstopdf}

\begin{document}


\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}
%\framesubtitle{\centerline{frame subtitle}}

\begin{algorithm}[H]
    \caption{Pseudocode for the GWO}
    \label{gwo}
    \begin{algorithmic}[1]
        %   \Procedure{Hybrid BAT-Genetic Algorithm}{}
        \\Input :Grey wolf population:$X_{i}(i = 1, 2, ..., n)$,Maximum Number of iteration:Max\_it
        \\Output :$X_{a}$ : Optimal Position(Optimized filter coefficients)
        \\Objective function : PSNR
        \hrule
        \\Initialize the Grey wolf population $X_{i} = (i=1,2, ...,n)$
        \\Initialize the coefficient vectors a, A, and C
        \State $\vec{A}=2\vec{a}\vec{r_1}-\vec{a}$
        \State $\vec{C}=2\vec{r_2}$
        \Comment where components of are linearly decreased from 2 to 0 over the course of iterations and,\\ are random vectors in $[0,1]$
        \For{all $X_{i}$}
        \State Calculate fitness $F(X_{i})$ of all $X_{i}$
        \EndFor
\algstore{myalg}
    \end{algorithmic}
\end{algorithm}
\end{frame}

\begin{frame}
\frametitle{\centerline{\textbf{INTRODUCTION}}}


      \begin{algorithm}[H]
     \ContinuedFloat
%     \caption{Pseudocode for the GWO}
     \begin{algorithmic}[1]
     \algrestore{myalg}
        \State Rank the gray wolf in descending order based on the fitness
        \State $X_{\alpha}$ = the first search agent
        \State $X_{\beta}$ = the second search agent
        \State $X_{\delta}$ = the third search agent 
        \State t=1;
        \While{t\textless Max\_it}
        \For{i=1:n}
        \State Update the position of the current search agent \mbox{$\vec{F}(t+1) = \frac{\vec{F_{1}}+\vec{F_{2}}+\vec{F_{3}}}{3}$}
        \EndFor
        \State Update $a$,$A$, and $C$
        \For{all $X_{i}$}
        \State Calculate fitness $F(X_{i})$ of all $X_{i}$
        \EndFor
        \State Update $X_{\alpha}$, $X_{\beta}$, and $X_{\delta}$
        \State t=t+1;
        \EndWhile
        \State Return the first best agent $X_{\alpha}$ found so far
        \\Post-processing the results and visualization
        %   \EndProcedure
    \end{algorithmic}
\end{algorithm}

\end{frame}

\end{document}

相关内容