Gonzalo Medina provided a nifty solution to "Automatically set description list labelwidth
based on widest label?." (The goal was to define a description
environment where the item text is automatically indented to the width of the widest label.)
I could replicate its success on a standalone basis, but when I incorporated it into my standard set of packages, it no longer produced the desired results. By a process of elimination, I discovered that simply loading the mathtools
package was sufficient to cause the problem.
I don't know where to begin to search for the conflict or a workaround, but I'm hoping someone with more experience, with mathtools
in particular, would spot it quickly.
Below is the MWE, straight out of Gonzalo's solution, except that I've inserted a commented-out \usepackage{mathtools}
. (I've experimented with the order of loading mathtools
but nothing solved the problem.)
Without mathtools
, the proper output looks like:
With mathtools
, the improper output looks like:
\documentclass{article}
\usepackage{enumitem}
\usepackage{environ}
%\usepackage{mathtools}
\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}