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 actually asked the exact question here: http://tex.stackexchange.com/questions/87646/problem-formatting-java-code-in-my-latex-document-overshooting-the-page

However I have tried using the solution I was given (which did work for the example I used them) but it seems that this does not work with the package I want to use (example below).

I have looked through the texdoc file for captions and floats and could not find anything on how to do it either.

\usepackage{float}
\usepackage{caption}
\begin{document}
\floatstyle{ruled}
\newfloat{program}{thp}{lop}
\floatname{program}{Program}
\begin{program}
\begin{verbatim}

   if(args.length>0){
       while(expression){

                BufferedReader xReader=new BufferedReader(new FileReader(IOUtil.fileName(args[0])));


               `BufferedReader yReader=new BufferedReader(new FileReader(IOUtil.fileName(args[1]))); } }`



\end{verbatim}
\caption{}
\end{program}
\end{document}
share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

enter image description here

This redefines the verbatim space to allow a break:

\documentclass{article}
\usepackage{float}
\usepackage{caption}
\begin{document}
\floatstyle{ruled}
\newfloat{program}{thp}{lop}
\floatname{program}{Program}
\begin{program}

\makeatletter
\def\@xobeysp{\ \hfil\penalty\z@\hfilneg}
\begin{verbatim}

   if(args.length>0){
       while(expression){

                BufferedReader xReader=new BufferedReader(new FileReader(IOUtil.fileName(args[0])));


               `BufferedReader yReader=new BufferedReader(new FileReader(IOUtil.fileName(args[1]))); } }`



\end{verbatim}
\caption{}
\end{program}
\end{document}
share|improve this answer
    
Hey that worked the only problem is it trailed to the bottom of the page and beyond. Any idea how I can stop that too? –  Magpie Jan 27 '13 at 16:26
1  
program is a float environment so a minipage so never breaks just put the verbatim in the normal text run if you want it to break over a page you can use the caption package to do captionof{program}{...}to caption the non-floating verbatim –  David Carlisle Jan 27 '13 at 16:31
    
Ah right. I think I had this once before thanks for clarifying. –  Magpie Jan 27 '13 at 16:35
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.