Discussion:
Can't center verbatim
(too old to reply)
blop
2006-02-22 14:04:17 UTC
Permalink
I have this in my .tex file:

\begin{center}
\scriptsize
\begin{verbatim}
void quicksort'(A,p,r)
{
while (p < r)
{
q = partition(A,p,r);
new_q = q/2;
quicksort'(A,p,new_q -1);
p = new_q + 1;

}
}
\end{verbatim}
\normalsize
\end{center}

But it does not get centered. What am I missing?
Enrico Gregorio
2006-02-22 14:20:05 UTC
Permalink
Post by blop
\begin{center}
\scriptsize
\begin{verbatim}
void quicksort'(A,p,r)
{
while (p < r)
{
q = partition(A,p,r);
new_q = q/2;
quicksort'(A,p,new_q -1);
p = new_q + 1;
}
}
\end{verbatim}
\normalsize
\end{center}
But it does not get centered. What am I missing?
The verbatim environment produces lines as wide as the text width,
so centering does nothing. Try the fancyvrb package.

Ciao
Enrico
blop
2006-02-22 14:24:32 UTC
Permalink
Ok I have now included that package and recompiled, but it still does
not get centered...
Maarten Bergvelt
2006-02-22 15:06:37 UTC
Permalink
Post by blop
Ok I have now included that package and recompiled, but it still does
not get centered...
You might want to make it easy for somebody to help you.

Minimal example?
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=minxampl
Ask questions?
http://www.tex.ac.uk/cgi-bin/texfaq2html?label=askquestion
--
Maarten Bergvelt
blop
2006-02-22 15:13:07 UTC
Permalink
I have made the minimal example, the only thing I changed was to
include the fancyvrb package as I wrote...but it still does not work. I
read the manual for fancyvrb and it seems that you need to make an
Environment where you can define center and then use this environment.
Maarten Bergvelt
2006-02-22 15:52:44 UTC
Permalink
Post by blop
I have made the minimal example, the only thing I changed was to
include the fancyvrb package as I wrote...but it still does not work. I
read the manual for fancyvrb and it seems that you need to make an
Environment where you can define center and then use this environment.
No you didn't. Look, I don't care if you don't want to be helped, suit
your self.
--
Maarten Bergvelt
Stephen Powell
2006-02-25 03:20:27 UTC
Permalink
Post by blop
I have made the minimal example, the only thing I changed was to
include the fancyvrb package as I wrote...but it still does not work. I
read the manual for fancyvrb and it seems that you need to make an
Environment where you can define center and then use this environment.
I've never used fancyvrb before but after 10 minutes reading the
manual I came up with this; is it close to what you want?

\documentclass{minimal}
\usepackage{fancyvrb}
\begin{document}
\begin{center}
\scriptsize
\begin{BVerbatim}
void quicksort'(A,p,r)
{
while (p < r)
{
q = partition(A,p,r);
new_q = q/2;
quicksort'(A,p,new_q -1);
p = new_q + 1;

}
}
\end{BVerbatim}
\end{center}
\end{document}
--
I just ate a whole package of Sweet Tarts and a can of Coke. I think I saw God.
-- B. Hathrume Duk
Dan Luecking
2006-02-23 00:09:06 UTC
Permalink
Post by blop
\begin{center}
\scriptsize
\begin{verbatim}
void quicksort'(A,p,r)
{
while (p < r)
{
q = partition(A,p,r);
new_q = q/2;
quicksort'(A,p,new_q -1);
p = new_q + 1;
}
}
\end{verbatim}
\normalsize
\end{center}
But it does not get centered. What am I missing?
That's not a tex file. It contains latex commands, but no
\documentclass, nor \begin{document, nor \end{document}.

I would try including a verbatim-related package like verbatim.sty
or fancyvrb.sty. Some allow you to change the command that places
each line.

Have you considered that its not really verbatim if you destroy
the relative indentation? Or did you want to center the whole
thing as a unit? If that is the case, the answer is the same as
any other block of text: wrap the verbatim environment
in a minipage of suitable size.


Dan
To reply by email, change LookInSig to luecking
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Continue reading on narkive:
Loading...