按用户定义的量移动描述

按用户定义的量移动描述

已设法在文本区域的开头启动列表标签,相当于

我想要以下输出

LABEL.1999-DEF8
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; "Quantum Fields and
  Strings: A Course for Mathematicians."  Vol. 1-2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.

其中“LABELxxx”从左边距开始(从无缩进的位置开始)。而以下段落以DESC.Deligne(构成环境主体)开头,按用户定义的尺寸向右移动。

但是我无法使在下一行开始的环境主体中提供的描述具有由第一个参数的值定义的水平#1移位Spar

添加#1并未\leftmargin证明会转移任何文本。

\documentclass[a4paper,10pt]{article}
\usepackage{geometry}

\ExplSyntaxOn

\NewDocumentEnvironment {Spar} { O{0.3cm} m }
  {
    \list {}
      {
        \setlength {\leftmargin} {\dimexpr\leftmargin+#1\relax}
        \setlength{\topsep}{0pt}
        \setlength{\partopsep}{0pt}
        \setlength{\parskip}{0pt}
        \setlength{\labelwidth}{0pt}
        %% \setlength{\itemindent}{-\leftmargin}
        \renewcommand* \makelabel [1]
          { \rlap { \parbox[b] {\linewidth} 
                      { 
                        %%\hspace*{\labelsep}
                        \normalfont\bfseries ##1
                        \endgraf\mbox{}
                      }
                  }
          %% \hspace{\leftmargin}
      }}
  \item[{[#2]}]
  }
    { \endlist }

\ExplSyntaxOff

\geometry { b5paper, 
  left=8mm, right=8mm, top=8mm, bottom=8mm,
  includehead, includefoot }

\begin{document}

\noindent X\dotfill X

\begin{Spar}{LABEL.1999-DEF8}
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; "Quantum Fields and
  Strings: A Course for Mathematicians."  Vol. 1-2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
\end{Spar}

\noindent X\dotfill X

\end{document}

答案1

为什么要使用单项列表?你可以使用enumitem,但是没有理由这样做。

\documentclass[a4paper,10pt]{article}
\usepackage{geometry}
\usepackage{enumitem}

\NewDocumentEnvironment{Spar}{ O{0.3cm} m }{%
  \itemize[
    wide,
    leftmargin=\dimeval{\leftmargini+#1},
    nosep,
    itemindent=-\leftmargin,
    labelsep=0pt,
    labelwidth=0pt,
    align=left,
    listparindent=0pt,
  ]
  \renewcommand*{\makelabel}[1]{%
    \parbox[b]{\linewidth}{\normalfont\bfseries [##1]}
  }%
  \item[#2]\mbox{}\par\nopagebreak
}
{\enditemize}

\geometry{
  b5paper, 
  left=8mm,
  right=8mm,
  top=8mm,
  bottom=8mm,
  includehead,
  includefoot
}

\begin{document}

\noindent X\dotfill X

\begin{Spar}{LABEL.1999-DEF8}
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
\end{Spar}

\noindent X\dotfill X

\begin{Spar}[3cm]{LABEL.1999-DEF8}
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
\end{Spar}

\end{document}

在此处输入图片描述

我只是使用命令,而不是环境和\leftskip

\documentclass[a4paper,10pt]{article}
\usepackage{geometry}
\usepackage{enumitem}

\NewDocumentCommand{\Spar}{O{0.3cm}m+m}{%
  \begingroup
  \setlength{\parindent}{0pt}%
  \setlength{\leftskip}{\leftmargini}% standard for first level lists
  \addtolength{\leftskip}{#1}%
  % the label
  \hspace*{-\leftskip}\parbox[b]{\linewidth}{\normalfont\bfseries [#2]}\par
  \nopagebreak\ignorespaces #3\par
  \endgroup
}

\geometry{
  b5paper, 
  left=8mm,
  right=8mm,
  top=8mm,
  bottom=8mm,
  includehead,
  includefoot
}

\begin{document}

\noindent X\dotfill X

\Spar{LABEL.1999-DEF8}{
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
}

\noindent X\dotfill X

\Spar[3cm]{LABEL.1999-DEF8}{
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
}

\end{document}

如果可选参数应该定义移位量,则第二个代码应该变成

\documentclass[a4paper,10pt]{article}
\usepackage{geometry}
\usepackage{enumitem}

\NewDocumentCommand{\Spar}{O{0.3cm}mm}{%
  \begingroup
  \setlength{\parindent}{0pt}%
  \setlength{\leftskip}{#1}
  % the label
  \hspace*{-\leftskip}\parbox[b]{\linewidth}{\normalfont\bfseries [#2]}\par
  \nopagebreak\ignorespaces #3\par
  \endgroup
}

\geometry{
  b5paper, 
  left=8mm,
  right=8mm,
  top=8mm,
  bottom=8mm,
  includehead,
  includefoot
}

\begin{document}

\noindent X\dotfill X

\Spar{LABEL.1999-DEF8}{
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
}

\noindent X\dotfill X

\Spar[0pt]{LABEL.1999-DEF8}{
  DESC.Deligne Pierre, Etingof Pavel, et al., 1999; ``Quantum Fields and
  Strings: A Course for Mathematicians.''  Vol. 1--2. With Freed Daniel
  S., Jeffrey Lisa C., Kazhdan David, Morgan John W., Morrison David R.,
  Witten Edward.
}

\end{document}

在此处输入图片描述

enumitem基础代码中,更改

leftmargin=\dimeval{\leftmargini+#1},

进入

leftmargin=#1,

答案2

首先确保宏可以生成您需要的形状。在您的例子中labelwidthleftmarginrightmargin必须设置为相同的值。如果您只想增加,请使用默认长度作为开始,并使用添加或减少\numexpr。始终使用数字来处理列表。

\NewDocumentEnvironment {Spar} { O{30pt} m } {% \list {} { \setlength{\topsep}{0pt} \setlength{\partopsep}{0pt} \setlength{\parskip}{0pt} \setlength{\labelwidth}{#1} \setlength\labelsep{0pt} \setlength{\itemindent}{0pt} \setlength{\leftmargin}{#1} \setlength{\rightmargin}{#1} \listparindent=\parindent \renewcommand* \makelabel [1] {\rlap{ \parbox[b] {\linewidth} { %%\hspace*{\labelsep} \normalfont\bfseries ##1 \endgraf\mbox{} } } }} \item[#2] } { \endlist }

相关内容