# Strange spacing when using lstlisting

I am trying to use the lstlisting package in order to show some code in my document. However, it aligns it to the right of the page, as opposed to left as expected.

\begin{lstlisting}[frame=single]
run.py -some -parameters -right -here
\end{lstlisting}


Would yield something like:

                                                          run.py -some -parameters -right -here


What can I do to fix this?

• It would be helpful if you composed a fully compilable MWE including \documentclass and the appropriate packages that reproduces the problem. While solving problems can be fun, setting them up is not. Then, those trying to help can simply cut and paste your MWE and get started on solving the problem. – Peter Grill May 5 '14 at 1:20
• Yes, sorry, I will keep this in mind for the future. – cgf May 5 '14 at 1:39

One cause of such a problem could be leading spaces, or tabs which are sometime harder to see depending on the settings. So, one could add an appropriate gobble=<number> to remove leading characters. Here is an example with and without gobble:

Applying showspaces=true option might be a good way to check if that is the case. Applying showspaces=true to the MWE below yields:

## Code:

\documentclass{article}
\usepackage{listings}

\begin{document}
\begin{lstlisting}[frame=single]
run.py -some -parameters -right -here
\end{lstlisting}

\begin{lstlisting}[frame=single,gobble=16]
run.py -some -parameters -right -here
\end{lstlisting}
\end{document}