[comp.text.tex] Centering verbatim text -- how?

jordan@unix.cis.pitt.edu (Kenneth D Jordan) (04/02/91)

How does one center a section of verbatim text in LaTeX?  Specifically, I
would like to mix code fragments; e.g.

                         main( int argc, char *argv[] )
                         {
                             printf("Hello, workd!\n");
                         }

in with regular text as shown here.  \tt works, but necessitates inserting
a bunch of escapes that I'd rather avoid.

--------------------------------------------------------------------------------
Nick Nystrom
Chemistry Department
University of Pittsburgh
nystrom@a.psc.edu
--------------------------------------------------------------------------------

em@dce.ie (Eamonn McManus) (04/03/91)

jordan@unix.cis.pitt.edu (Kenneth D Jordan) writes:
>How does one center a section of verbatim text in LaTeX?  Specifically, I
>would like to mix code fragments ... in with regular text...

The problem is that verbatim mode sets every line as a paragraph, and
paragraphs always have width \hsize.  The way to centre would be to
have each line set as a row in a \halign instead; this is the best way
to have the width of the verbatim section be the width of the longest
line.  Hacking verbatim to do this is not impossible.

To my mind, though, indenting the code fragments looks at least as good as
centring and is easier to do.  My cprog style (plug) has a parameter
\cprogindent for this purpose.

,
Eamonn