3

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

3
  • @all, please see my update. This bad behavior only appears for inline inclusion. For external file inclusion, the problem vanishes. :-) Jan 6, 2011 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. Jan 6, 2011 at 10:06
  • @Hendrik. OK :-) Jan 6, 2011 at 10:15

1 Answer 1

4

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 ... ;-)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .