[Tex/LaTex] Indent a code listing in LaTeX

articleindentationlistings

For a little LaTeX document I am writing I would like to insert source code fields (in SQL) into my paper.

I found out that I can use the listings package for this, which works well so far:

\usepackage{color}
\definecolor{light-gray}{gray}{0.95}

\usepackage{listings} 
\lstset{numbers=right, 
                numberstyle=\tiny, 
                breaklines=true,
                backgroundcolor=\color{light-gray},
                numbersep=5pt} 
\lstset{language=SQL} 

This works well so that I can insert code listings like:

\begin{lstlisting}{insert}
INSERT INTO Tabelle (Spalte1, Spalte2, Spalte3) VALUES (Wert1, Wert2, Wert3);
\end{lstlisting}

What it shows me are light-gray boxes containing the code, but they start at the beginning of the line, just like the text. I now would like to have code listings automatically being indented a bit. So that the gray box doesn't start at the level of the text.

Can anybody tell me how to achieve this? I am quite a beginner at working with LaTeX… would be great if anyone could help!

Best Answer

The listings package allows you to change the margins (see section 4.10 of the documentation.)

\lstset{numbers=right, 
                numberstyle=\tiny, 
                breaklines=true,
                backgroundcolor=\color{light-gray},
                numbersep=5pt,
                xleftmargin=.25in,
                xrightmargin=.25in} 

Adjust as necessary.