3

I have got the following problem using an alltt environment in a beamer document. I placed an alltt environment inside a block environment. Then all line breaks are correct in the output document. But if I enclose the block with an \only command, the line breaks in the alltt environment are removed. How can I remove this problem? A minimal example is:

\documentclass{beamer}

\usepackage[utf8x]{inputenc}
\usepackage{default}
\usepackage{xcolor}
\usepackage{alltt}

\begin{document}
\begin{frame}[t,fragile]
This text should be on all 3 overlays.
\only<1,2>{
\begin{block}<1,2>{}
\footnotesize
\begin{alltt}
[user@{\color{red}nodeXX} ~]\$ {\color{blue}module load comp/gcc/4.5.1}
[user@{\color{red}nodeXX} ~]\$ {\color{blue}module load mpi/openmpi/1.6.0}
[user@{\color{red}nodeXX} ~]\$ {\color{blue}mpirun ./prgm}
\end{alltt}
\end{block}
\begin{block}<2>{}
Next Step...
\end{block}
}
\begin{block}<3>{}
This block is shown next directly below the text.  
\end{block}

\end{frame}
\end{document}

If the \only is commented out, the alltt environment creates the lines breaks but block 3 is at the bottom of the page.

1 Answer 1

3

You can use \defverbatim:

\documentclass{beamer}
\usetheme{Boadilla}
\usepackage[utf8x]{inputenc}
\usepackage{default}
\usepackage{xcolor}
\usepackage{alltt}

\begin{document}

\begin{frame}[t,fragile]
\defverbatim[colored]\mycode{
\footnotesize
\begin{alltt}
[user@{\color{red}nodeXX} ~]\$ {\color{blue}module load comp/gcc/4.5.1} 
[user@{\color{red}nodeXX} ~]\$ {\color{blue}module load mpi/openmpi/1.6.0} 
[user@{\color{red}nodeXX} ~]\$ {\color{blue}mpirun ./prgm}
\end{alltt}
}

This text should be on all 3 overlays.
\only<1,2>{
\begin{block}<1,2>{}
\mycode
\end{block}
}
\begin{block}<2>{}
Next Step...
\end{block}
\begin{block}<3>{}
This block is shown next directly below the text.  
\end{block}

\end{frame}
\end{document}

enter image description here

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.