為什麼投影機中沒有顯示演算法/偽代碼的區塊?

為什麼投影機中沒有顯示演算法/偽代碼的區塊?

雖然beamer中有很多塊,但我沒有找到任何algorithm/pseudo-code塊。

為什麼沒有algorithm塊?或者,演算法是否有任何替代區塊?或者,演算法區塊是否排版不好?

在此輸入影像描述

\documentclass{beamer}
\usetheme{Madrid}
\begin{document}
\begin{frame}
  \begin{exampleblock}{Example}
    This is a example block
  \end{exampleblock}
  \begin{alertblock}{Alert}
    This is a alert block
  \end{alertblock}
  \begin{theorem}{This is a theorem block}
  \end{theorem}
  \begin{definition}{This is a definition block}
  \end{definition}
\end{frame}
\end{document}

答案1

通用block環境可以處理任意區塊名稱。包含偽代碼(或真實代碼)範例非常簡單:

\documentclass{beamer}
\usepackage{listings}
\lstset{language=Python}

\begin{document}
\begin{frame}[fragile]
\begin{block}{Algorithm}
\begin{lstlisting}
  for i in range(10):
      foo(arg1, arg2)
  bar = qux()
\end{lstlisting}
\end{block}
\end{frame}
\end{document}

在此輸入影像描述

相關內容