使用 enumitem 在描述列表中的项目上悬挂缩进

使用 enumitem 在描述列表中的项目上悬挂缩进

使用enumitem,我怎样才能让描述列表中的单个项目oneproperty具有悬挂缩进,就像枚举列表中的项目一样propertylist

\documentclass{memoir}

\usepackage{enumitem}
\usepackage{xpatch}

\newlist{proplis}{enumerate}{1}
\newenvironment{propertylist}[1]{%
  \setlist[proplis,1]{%
  wide,leftmargin=*,label=\textsf{\upshape(#1\arabic*)}}\begin{proplis}%
  \itshape}
  {\end{proplis}}

% Hack for labeled items in description list
\makeatletter
\xpatchcmd{\enit@description@i}{%
  \labelsep\z@
}{%
  \phantomsection
  \let\org@label\label
  \let\label\@gobble
  \protected@edef\@currentlabel{##1}%
  \let\label\org@label
  \labelsep\z@
}{}{\undefined}
\makeatother

% NB: must enclose actual item name in parens, \label[...] in optional arg!
\newlist{oneproplis}{description}{1}
\newenvironment{oneproperty}[1]{%
\setlist[oneproplis,1]{%
    font=\normalfont\textsf,
    itemindent=0pt,
    wide,leftmargin=*,
    itemsep=0pt,topsep=2pt,
    format={\normalfont\textsf},
    }\begin{oneproplis}%
  \itshape}
  {\end{oneproplis}}


\begin{document}

A thingamajig is an object having properties:
\begin{propertylist}{O}

\item This is the penultimate and next-to-last property, which precedes the last property but follows any other property. 
%And we could repeat ourselves: This is the penultimate and next-to-last property, which precedes the last property but follows any other property.

\item This is final!.

\end{propertylist}

Much simpler is the property:

\begin{oneproperty}

\item[(SN)]\label{property:SN}

This is a list that has just one item, set up as a description list and configured so as to take an argument that will become its name.

\end{oneproperty}

\end{document}

想要在“oneproperty”描述列表项上悬挂缩进。

当然,缩进的量取决于物品标签的宽度。

解决方案的想法

有没有什么方法可以“伪造”这种情况,使用enumerate列表但抑制数字 - 类似于......

\newlist{oneproplis}{enumerate}{1}
\newenvironment{onepropertylist}[1]{%
\setlist[newoneproplis,1]{% 
   wide,leftmargin=*,
   label=\textsf{\upshape(#1)\swallow}}\begin{oneproplis}%
   \itshape}%
   {\end{oneproplis}}

...哪里\swallow具有与 say 相同的作用,\arabic但是,不是格式化项目编号,而是抑制它?

答案1

如果您知道最广泛的描述标签,则解决方案是:

\documentclass{memoir}

\usepackage{enumitem}
\usepackage{xpatch}

\newlist{proplis}{enumerate}{1}
\newenvironment{propertylist}[1]{%
  \setlist[proplis,1]{%
  wide,leftmargin=*,label=\textsf{\upshape(#1\arabic*)}}\begin{proplis}%
  \itshape}
  {\end{proplis}}

% Hack for labeled items in description list
\makeatletter
\xpatchcmd{\enit@description@i}{%
  \labelsep\z@
}{%
  \phantomsection
  \let\org@label\label
  \let\label\@gobble
  \protected@edef\@currentlabel{##1}%
  \let\label\org@label
  \labelsep\z@
}{}{\undefined}
\makeatother
\newlength{\desclabelwd}
\settowidth{\desclabelwd}{\textsf{(SN)}}
% NB: must enclose actual item name in parens, \label[...] in optional arg!\dimexpr7mm + \labelsep\relax,
\newlist{oneproplis}{description}{1}
\newenvironment{oneproperty}[1]{%
\setlist[oneproplis,1]{%
    font=\normalfont\textsf,
    wide, leftmargin=\dimexpr\parindent+\desclabelwd+\labelsep,
    itemsep=0pt, topsep=2pt,
    format={\normalfont\textsf},
    }\begin{oneproplis}%
  \itshape}
  {\end{oneproplis}}

\begin{document}

A thingamajig is an object having properties: A thingamajig is an object having properties:
\begin{propertylist}{O}

\item This is the penultimate and next-to-last property, which precedes the last property but follows any other property.
%And we could repeat ourselves: This is the penultimate and next-to-last property, which precedes the last property but follows any other property.

\item This is final!.

\end{propertylist}

Much simpler is the property:

\begin{oneproperty}

\item[(SN)]\label{property:SN}

This is a list that has just one item, set up as a description list and configured so as to take an argument that will become its name. Some more text. Some more text. Some more text.

\end{oneproperty}

\end{document} 

在此处输入图片描述

相关内容