4

The cleveref package allows users to specify label types using the command \crefname. Unfortunately, using these label types with the amsart or amsbook classes causes the position of the equation number to depend on the label length. How can I make equation number positioning independent of label length?

Concretely, if you consider the following MWE, then second equation number is to the left of the first, and the third is far to the left of the second. All equation numbers should be aligned under the first equation number.

\documentclass{amsart}
\usepackage{cleveref}

\crefname{foo}{bar}{baz}

\begin{document}
\begin{gather}
  \label{eq:a-really-long-label-but-equation-number-is-well-placed}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
\end{gather}

\begin{gather}
  \label[foo]{eq:short-okish}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
\end{gather}

\begin{gather}
  \label[foo]{eq:long-so-out-in-margin}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
\end{gather}
\end{document}

enter image description here

5
  • It seems a bug in cleveref.
    – egreg
    Commented Aug 17, 2021 at 20:37
  • 1
    amsmath measures the equation, and it sets \label to gobble for this, but with the optional argument this doesn't work, it leaves the label text in the stream. Commented Aug 17, 2021 at 20:39
  • The issue doesn’t seem to arise if the article document class is in use and the amsmath package is loaded by hand.
    – Mico
    Commented Aug 17, 2021 at 21:06
  • @Mico you get it there too, by default you see only overfull boxes, but if you use leqno the labels are misplaced too. Commented Aug 17, 2021 at 21:13
  • @UlrikeFischer - Thanks. I hadn't considered the leqno option (which is employed by the amsart document class by default).
    – Mico
    Commented Aug 17, 2021 at 23:57

1 Answer 1

4

It's a problem with cleveref that doesn't correctly patch \gmeasure@ and does

\let\label\@gobble

instead of using some macro that also gobbles an optional argument.

\documentclass{amsart}
\usepackage{cleveref}
\usepackage{xpatch}

\crefname{foo}{bar}{baz}

\makeatletter
\newcommand{\@gobbleoptone}[2][]{}
\xpatchcmd{\gmeasure@}{\let\label\@gobble}{\let\label\@gobbleoptone}{}{}
\makeatother

\begin{document}

\begin{gather}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
  \label{eq:a-really-long-label-but-equation-number-is-well-placed}
\end{gather}

\begin{gather}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
  \label[foo]{eq:short-okish}
\end{gather}

\begin{equation}
  \mathsf{blah blah blah blah blooh blooh blooh blooh} \to \mathsf{blah blah blah blah blah beep boop}
  \label[foo]{eq:long-so-out-in-margin}
\end{equation}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .