2

Desired output

I'm trying to copy an example from a paper which comprises two code snippets next to each other and separated by a symbol, as shown in the image. But I'm not sure how to do something like this. It looks like verbatim code but that stuff is fragile.

Bonus points if it works in Beamer, but any clues to solve this is appreciated.

6

Use 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}

This works out of the box also with beamer, the only care is to use

\begin{frame}[fragile]

enter image description here

0
6

Beamer columns are your friend!

\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}
4

You could easily store the contents of the algorithms in boxes, and then use the boxes in whichever structure you're comfortable with (like tabular, or the like):

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.