# Defining my indentation environment

I define my indentation environment as follows:

\newenvironment{myindentpar}[1]%
{\begin{list}{}%
{\setlength{\leftmargin}{#1}}%
\item[]%
}
{\end{list}}


Here is a minimal example.

\documentclass{article}
\usepackage{listings}
\lstloadlanguages{[5.2]Mathematica}

\newenvironment{myindentpar}[1]%
{\begin{list}{}%
{\setlength{\leftmargin}{#1}}%
\item[]%
}
{\end{list}}

\begin{document}

We start by defining the Langrangian (or material) description of the motion. We also provide the displacement field.
\begin{myindentpar}{2cm}
\begin{lstlisting}
T[X_, Y_, Z_] = {X + Y Tan[\[Gamma]], Y, Z};
u[X_, Y_, Z_] = T[X, Y, Z] - {X, Y, Z};
\end{lstlisting}
\end{myindentpar}
Let consider a unit square.

\end{document}


How can I get rid of the spacing between the listing and the text above it?

## 1 Answer

There are two sourced for the big vertical space: \topsep and the fact that lstlistings after \item[] will start a new line.

You're using the wrong tool, the xleftmargin option does the job.

\documentclass{article}
\usepackage{listings}

\lstloadlanguages{[5.2]Mathematica}

\lstset{% sorry, I can't stand listings in any different fashion
basicstyle=\ttfamily,
columns=fullflexible,
keepspaces,
}

\newenvironment{myindentpar}[1]%
{\begin{list}{}%
{\setlength{\leftmargin}{#1}}%
\item[]%
}
{\end{list}}

\begin{document}

We start by defining the Langrangian (or material) description of
the motion. We also provide the displacement field.
\begin{myindentpar}{2cm}
\begin{lstlisting}
T[X_, Y_, Z_] = {X + Y Tan[\[Gamma]], Y, Z};
u[X_, Y_, Z_] = T[X, Y, Z] - {X, Y, Z};
\end{lstlisting}
\end{myindentpar}
Let consider a unit square.

We start by defining the Langrangian (or material) description of
the motion. We also provide the displacement field.
\begin{lstlisting}[xleftmargin=2cm]
T[X_, Y_, Z_] = {X + Y Tan[\[Gamma]], Y, Z};
u[X_, Y_, Z_] = T[X, Y, Z] - {X, Y, Z};
\end{lstlisting}
Let consider a unit square.

\end{document}