[Tex/LaTex] How to align description item labels on the right

descriptionhorizontal alignmentlists

I have seen description-list-with-right-alignment-of-labels that explains, how to align description labels on the right. However the presented solution sets the lengths globally whereas I look for a local solution, meaning to specify the width for each environment separately. Is there a way telling each description environment what the broadest item is:

\documentclass{article}
\usepackage{enumitem}
\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}

\setlist[description]{style=multiline,topsep=10pt,leftmargin=5cm,font=\textbf,align=parright}

\begin{document}

\begin{description}
\item[aaa] some text
\item[bbbbbb] some more text
\item[ccccccccc] and some text
\end{description}


\begin{description}
\item[aaaaaaa] some text
\item[bbbbbbbbbbbbbbb] some more text
\item[ccccccccccccccccccccccc] and some text
\end{description}

\end{document}

Best Answer

You can use the \widthof{} from the calc package to compute the correct width for the labelwidth on a per description list to obtain:

enter image description here

The parameter passed to the \widthof{} should be the widest element in the description list and also note that since the label is set in bold font, we need to ensure that the measurements are done with \bfseries applied:

\documentclass{article}
\usepackage{calc}
\usepackage{enumitem}
\SetLabelAlign{parright}{\parbox[t]{\labelwidth}{\raggedleft#1}}

\begin{document}
\begin{description}[labelwidth=\widthof{\bfseries ccccccccc},align=parright]
    \item[aaa]       some text
    \item[bbbbbb]    some more text
    \item[ccccccccc] and some text
\end{description}

\begin{description}[labelwidth=\widthof{\bfseries ccccccccccccccccccccccc},align=parright]
    \item[aaaaaaa]                 some text
    \item[bbbbbbbbbbbbbbb]         some more text
    \item[ccccccccccccccccccccccc] and some text
\end{description}
\end{document}