2

With enumitem, how can I get the single item in the oneproperty description list to have a hanging indent, just like the items in the propertylist enumerate list?

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

Want hanging indent on "oneproperty" description list item.

The amount of the indent should depend on the width of the item's label, of course.

Idea for a solution

Is there some way to "fake" this, using an enumerate list but suppressing the number — something like ...

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

... where \swallow has the same role that, say \arabic would have but, instead of formatting the item's number, just suppresses it?

  • The wide key is supposed to produce items that look like ordinary paragraphs. I think it is contradictory to what you want here. – Ruixi Zhang Nov 1 '18 at 16:37
  • @RuixiZhang: But the wide key does do what I want for propertylist. – murray Nov 1 '18 at 18:13
2

A solution if you know the widest description label:

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

enter image description here

  • I do know the widest such description label, so that will work. Is there some way, though, to modify the environment so that the parentheses around the label are automatically inserted? – murray Nov 2 '18 at 0:45
  • 1
    This gives a fixed-length hanging indentation for all such one-item description lists, with the hanging indentation fixed at the width of \desclabelwd. But I need a variable-length hanging indentation, which will vary according to the width of the particular label. Thus if in the \begin{oneproperty}...\end{oneproperty}I use \item[(S)] or \item[(SN)] or \item[(SNXYZ)] I need different amounts. – murray Nov 2 '18 at 17:01
  • 1
    You can use \settowidth{\desclabelwd}{your label}} before each such environment. I tried to incorporate it with an optional argument at the beginning of the environment ((which would be the ideal solution), but couldn't make it work. – Bernard Nov 2 '18 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.