I would like to set the description's width automatically to the widest. The solution at Automatically set description list `labelwidth` based on widest label? works for me, except if I have the mathtools package loaded.
The following MWE, which is the same as Gonzalo's but loads the mathtools package, is below:
\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}
If I remove mathtools, it works. But I need mathtools.
0.0pt. – cfr Nov 24 '16 at 04:10mathtoolsdirectly, butmathtoolsload thecalcpackage which changes how\setlengthbehave. This is the source of your problems. – daleif Nov 24 '16 at 13:40