答案1
使用fancyvrb
:
\documentclass{article}
\usepackage{fancyvrb}
\begin{document}
\begin{BVerbatim}[baseline=c]
local r1;
x := 1;
r1 := y;
if (r1 = 0) then
critical region
\end{BVerbatim}
\quad$\parallel$\quad
\begin{BVerbatim}[baseline=c]
local r2;
y := 1;
r2 := x;
if (r2 = 0) then
critical region
\end{BVerbatim}
\end{document}
这也是开箱即用的beamer
,唯一需要注意的是使用
\begin{frame}[fragile]
答案2
Beamer 柱是你的朋友!
\documentclass{beamer}
\begin{document}
\begin{frame}[fragile]
\begin{columns}[onlytextwidth]
\begin{column}{.4\textwidth}
\begin{verbatim}
local r1
x := 1
\end{verbatim}
\end{column}
\begin{column}{.05\textwidth}
\rotatebox{90}{=}
\end{column}
\begin{column}{.4\textwidth}
\begin{verbatim}
local r2
y := 1
\end{verbatim}
\end{column}
\end{columns}
\begin{center}
Dekker's Mutal Exclusion Algorithm
\end{center}
\end{frame}
\end{document}
答案3
您可以轻松地将算法的内容存储在盒子中,然后以您熟悉的任何结构使用这些盒子(例如tabular
,或类似的):
\documentclass{beamer}
\usepackage{varwidth}
\newsavebox{\leftCode}
\newsavebox{\rightCode}
\begin{document}
\begin{lrbox}{\leftCode}
\begin{varwidth}{\linewidth}
\obeylines\obeyspaces\ttfamily
local r1;
x := 1;
r1 := y;
if (r1 = 0) then
~~critical region
\end{varwidth}
\end{lrbox}
\begin{lrbox}{\rightCode}
\begin{varwidth}{\linewidth}
\obeylines\obeyspaces\ttfamily
local r2;
y := 1;
r2 := x;
if (r2 = 0) then
~~critical region
\end{varwidth}
\end{lrbox}
\begin{frame}
\centering
\usebox{\leftCode} \quad
$\parallel$ \quad
\usebox{\rightCode}
\bigskip
(a) Dekker's Mutual Exclusion Algorithm
\end{frame}
\end{document}