Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

listings package and position

1,970 views
Skip to first unread message

alfatau

unread,
Sep 4, 2009, 9:04:57 AM9/4/09
to
Hello, i'm enjoying the listings package for writing code, but i would
want to get the code frame centered on the page.

the following command

\begin{center}
\begin{lstlisting}
....
code
....
\end{lstlisting}
\end{center}

rests aligned to the left of the page.
I also tried with the \centered command, but without success.

The only thing that "worked" was to encapsulate the lstlisting
environment inside a table as follows:

\begin{table}[!ht]
\centering
\begin{tabular}{c}

\begin{lstlisting}
....
code
....
\end{lstlisting}

\end{tabular}
\end{table}

even if in this i can't correctly display the captions and labels.

Do you know a way to get a "native" centered listing, without losing
other caption and style features of that package?

Thank you for your attention.
Alessandro

Ignasi

unread,
Sep 5, 2009, 8:36:45 AM9/5/09
to
On Sep 4, 3:04 pm, alfatau <aghidottipio...@gmail.com> wrote:
> Hello, i'm enjoying the listings package for writing code, but i would
> want to get the code frame centered on the page.
>
> the following command
>
> \begin{center}
> \begin{lstlisting}
> ....
>  code
> ....
> \end{lstlisting}
> \end{center}
>

Try with

{\par\centering
\begin{lstlisting}
...
\end{lstlisting}
\par}

Ignasi

alfatau

unread,
Sep 5, 2009, 4:19:37 PM9/5/09
to
>
> Try with
>
> {\par\centering
> \begin{lstlisting}
> ...
> \end{lstlisting}
> \par}
>
> Ignasi

Thank you very much for having replied.
Your proposal still not works.
I looked around for examples, and noone seems interested to centered
listings.
Do you have some other proposals?

Thank you for your attention
Alessandro

silent bob

unread,
Oct 2, 2009, 7:43:47 AM10/2/09
to
Well, I do not have a solution, but if you try

\begin{center}
\begin{lstlisting}[caption={original program}, frame=trBL]


....
code
....
\end{lstlisting}
\end{center}

you'll see that "listings" package actually uses the *whole* length of
the line/paper/whatever.
So I would think that a variant of listings, which uses "varwidth"
instead of "minipage" or whatever, would solve your problem.
Regretfully I am not that much of a latex guru to write such a hack
myself.
Best regards,
bob

Carl Riehm

unread,
Oct 2, 2009, 3:38:45 PM10/2/09
to

I just installed WinEdt/Miktex in a new computer. When I try to compile a
document (which works perfectly well in my "old" computer), I get the
error message
("C:\Program Files\MikTeX 2.8\tex\latex\base\makeidx.sty"

LateX Error: Command \see already defined.
Or name \end... illegal, see p.192 of the manual.
See LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

l.41 \newcommand*\see[2](\emph(\seename> #1)

?"

The preamble contains

\documentclass{fim-l}
\usepackage{latexsym,srcltx}
\usepackage{amssymb}
\usepackage{amsxtra}
\usepackage{makeidx}
\makeindex
\usepackage{amsmath}
\input xypic
\input crr.tex
\bibliographystyle{plain}
\usepackage{glossary}
\makeglossary
\newcommand{\gloss}[3]{\glossary{name={#1},description={#2},sort={#3}}}
\usepackage{paralist}

(fim-l is an AMS style file)

Help!

Carl

Joseph Wright

unread,
Oct 2, 2009, 4:11:44 PM10/2/09
to

It's in the class (which is *not* standard):

\newcommand\seename{see also}%
\newcommand\see[2]{{\em \seename\/} #1}%
--
Joseph Wright

0 new messages