[Tex/LaTex] How to align source code produced by listings package with main paragraph text

horizontal alignmentindentationlistings

I'm using the latex listings package for the first time to format some HTML. I'm noticing that by default, the html code is being pushed further left than the main paragraph text of my document. Is there any simply option or way of specifying to listings that all source code should have the same margin width on the left as my general paragraph text does?

For reference, my latex code thus far is as follows:

\begin{lstlisting}[language=html]
<html lang=``en">
<head>...</head>
<body>
...
   <img src=``http://cnn.com/af/pic.gif"></img>
...
</body>
</html>
\end{lstlisting}

edit: I've isolated this down to only happening when I add line numbers to the listing using:

\lstset{
numbers=left
}

Minimum working example:

\documentclass{article}
\usepackage{lipsum,listings}
\begin{document}
\lstset{
numbers=left
}
\lipsum[1]
\begin{lstlisting}[language=html]
<html lang=``en">
<head>...</head>
<body>
...
<img src=``http://cnn.com/af/pic.gif"></img>
...
</body>
</html>
\end{lstlisting}
\end{document}

So is there a way to get the line numbers to align with the general paragraph text?

Best Answer

Works fine for me too! My guess is that you should check your lstset command, you probably need to adjust the margins (xleftmargin). listings have an option for virtually everything:

  \lstset{
%frame=tblr,
    framesep=5pt,
basicstyle=\normalsize\ttfamily,
showstringspaces=false,
keywordstyle=\itshape\color{blue},
%identifierstyle=\ttfamily,
stringstyle=\color{Maroon},
commentstyle=\color{black},
rulecolor=\color{Gray},
xleftmargin=5pt,
xrightmargin=5pt,
aboveskip=\bigskipamount,
belowskip=\bigskipamount,
   %backgroundcolor=\color{LightGray!.50}
  }