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.

I want to show my C# code snippet on the presentation slides using beamer. Because the code is long, I set the frame to be breakable using the frame option allowframebreaks. The code now can be shown in several frames. Unfortunately, the tab alignment in the original source no longer be preserved.


alt text


\documentclass[dvipsnames,cmyk]{beamer}
\usepackage{listings}

\lstset%
{%
   language=[Sharp]C,
   backgroundcolor=\color{Black},
   basicstyle=\color{White}\tiny\ttfamily,
   keywordstyle=\color{Orange},
   identifierstyle=\color{Cyan},
   stringstyle=\color{Red}, 
   commentstyle=\color{Green},  
   breaklines=true,
   breakatwhitespace=true,
   tabsize=10,
   showstringspaces=false%
}



\begin{document}
\begin{frame}[allowframebreaks,fragile]{MyListing}
\begin{lstlisting}
using System;

publid delegate void Foo(object o);

public class Program: object
{
 public static void Main(string[] args)
 {
   Console.WriteLine("Hello World");//This is a comment.
   /*This is a comment too.*/
 }
 public static void PSTricks(this object)
 {
   Say("I Love PSTricks!");

   Say("I Love PSTricks!");

   Say("I Love PSTricks!");

   Say("I Love PSTricks!");
 }

 public static void LaTeX(this object)
 {
   Say("I Love LaTeX too!");

   Say("I Love LaTeX too!");

   Say("I Love LaTeX too!");

   Say("I Love LaTeX too!");
 }

 public void Say(System.String message)
 {
   System.Text.StringBuilder sb=new System.Text.StringBuilder();

   sb.Append(messange);

   Console.WriteLine(sb);
 }
}
\end{lstlisting}
\end{frame}
\end{document}

Edit 1:

This bad behavior only happens for the inline inclusion.

The inclusion from an external file works well as shown in the following figure.

alt text

share|improve this question
    
@all, please see my update. This bad behavior only appears for inline inclusion. For external file inclusion, the problem vanishes. :-) –  xport Jan 6 '11 at 7:55
    
Herbert is right, you should try and make your examples miminal. To still reach the page break, use can use, e.g., \setlength\paperheight{2cm}. Moreover, please don't post overly long screen shots! A few lines are quite sufficient, and even better: Then it is easier to compare the screenshots. –  Hendrik Vogt Jan 6 '11 at 10:06
    
@Hendrik. OK :-) –  xport Jan 6 '11 at 10:15
add comment

1 Answer

up vote 2 down vote accepted

That cannot work, because fragile material has to written into an external temporary file and then read back by beamer. The tabs get lost here. Use it this way:

\documentclass[dvipsnames,cmyk]{beamer}

\usepackage{listings}

\begin{document}

\defverbatim[colored]\Lst{%
\begin{lstlisting}[tabsize=2,showtabs,frame=single]
using System;
                publid delegate void Foo(object o);
\end{lstlisting}}

\begin{frame}[allowframebreaks]{MyListing}
\Lst
\end{frame}

\end{document}

and by the way: please provide minimal examples ... ;-)

share|improve this answer
add comment

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.