I'm excited to have found a way to adjust the label width for a description list automatically according to the widest label (from Gonzalo Medina's answer to this question). Here's the code Gonzalo Medina wrote:
\documentclass{article}
\usepackage{enumitem}
\usepackage{environ}
\newlength\widest
\makeatletter
\NewEnviron{ldescription}{%
\vbox{%
\global\setlength\widest{0pt}%
\def\item[##1]{%
\settowidth\@tempdima{\textbf{##1}}%
\ifdim\@tempdima>\widest\global\setlength\widest{\@tempdima}\fi%
}%
\setbox0=\hbox{\BODY}%
}
\begin{description}[
leftmargin=\dimexpr\widest+0.5em\relax,
labelindent=0pt,
labelwidth=\widest]
\BODY
\end{description}%
}
\makeatother
\begin{document}
\begin{ldescription}
\item[Short] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\item[A really really long label] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\end{ldescription}
\begin{ldescription}
\item[Short] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\item[A medium label] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\end{ldescription}
\end{document}
I was wondering, though, whether it's possible to make this environment "nestable." Simply trying to nest it as I would "description" or "enumerate" did not work:
\documentclass{article}
\usepackage{enumitem}
\usepackage{environ}
\newlength\widest
\makeatletter
\NewEnviron{ldescription}{%
\vbox{%
\global\setlength\widest{0pt}%
\def\item[##1]{%
\settowidth\@tempdima{\textbf{##1}}%
\ifdim\@tempdima>\widest\global\setlength\widest{\@tempdima}\fi%
}%
\setbox0=\hbox{\BODY}%
}
\begin{description}[
leftmargin=\dimexpr\widest+0.5em\relax,
labelindent=0pt,
labelwidth=\widest]
\BODY
\end{description}%
}
\makeatother
\begin{document}
\begin{ldescription}
\item[Short] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\item[A label with a nested list] I would like a nested list here.
\begin{ldescription}
\item[Short] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\item[A long label] text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text
\end{ldescription}
\end{ldescription}
\end{document}
Particularly:
(1) I would like each list/nested list to have its own label width, equal to the width of the widest label in that particular list (not taking into account any label from its parent list or any label from a list nested in it); and
(2) I would like to be able to change the alignment of the labels (i.e. be able to choose between "align=left" and "align=right") for each list/nested list.
I would not mind having to define multiple environments (as long as I don't have to specify how many nested levels the document is going to have (i.e., as long as the process is automated)); my primary goal is to have this done automatically.
