定义我的缩进环境

定义我的缩进环境

我定义我的缩进环境如下:

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

这是一个最小的例子。

\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}

我怎样才能消除列表和其上方的文本之间的间距?

答案1

巨大的垂直空间有两个来源:\topsep一是lstlistings之后\item[]将开始一条新线路。

您使用的工具不正确,xleftmargin选项可以完成工作。

\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}

enter image description here

相关内容