Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.
\begin{frame}{Beispiel Mergesort}
    \begin{alltt}
            mergesort :: (Ord a, Trans a) => [a] -> [a]

            mergesort []   =  []

            mergesort [x]  =  [x]

            mergesort xs   =  sortmerge (process mergesort \# xs1)

                                    (process mergesort \# xs2)

                 where (xs1,xs2) = unshuffle xs
    \end{alltt}
\end{frame}

I'm doing a beamer presentation and try to display some source code, but I'm loosing all intendation, all whitespaces get merged into a single space. (not only at the beginning of the lines, but also around the '=' characters)

I don't know what I'm doing wrong.

Can someone help?

Cheers,

Lukas

share|improve this question
1  
Welcome to TeX.SX! I guess you want \begin{frame}[fragile]\frametitle{Beispiel Mergesort} –  egreg Jul 13 at 14:54
    
you, sir, are brilliant! thanks! –  Whadupapp Jul 13 at 14:59

1 Answer 1

Frames containing verbatim material should be declared fragile; also you don't really want that dramatic indentation, which will be kept in the listing.

\documentclass{beamer}
\usepackage{alltt}
\begin{document}
\begin{frame}[fragile]
\frametitle{Beispiel Mergesort}
\begin{alltt}
mergesort :: (Ord a, Trans a) => [a] -> [a]

mergesort []   =  []

mergesort [x]  =  [x]

mergesort xs   =  sortmerge (process mergesort \# xs1)

                      (process mergesort \# xs2)

    where (xs1,xs2) = unshuffle xs
\end{alltt}
\end{frame}

\end{document}

I think it is better to use the \frametitle command rather than an additional argument to \begin{frame}.

enter image description here

Instead of alltt you can use the semiverbatim environment, which doesn't require an additional package, but still requires [fragile].

share|improve this answer
    
thanks! Actually the tabs in front of the line don't seem to matter, those get killed by tex, just the intendation using spaces is kept. So I keep my tabs and get a nice looking tex code ;-) Thank you =) –  Whadupapp Jul 13 at 15:01
    
@Whadupapp In order my files don't have any TAB character, my editor does exactly nothing when the TAB key is hit. –  egreg Jul 13 at 15:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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