6

I am finding misaligned figure captions when using TeXlive 2021 with amsart. A test file is here:

\documentclass{amsart}
\begin{document}

\hbox to\hsize{X\hfil \TeX{Live} 2021 on Mac\hfil X}

\begin{figure}[h]
\hbox to\hsize{X\hfil X\hfil X}
\caption{XXXXX}
\end{figure}
\end{document}

The first hbox is just to show the margins. Running with TeXlive 2021 (June 2021) on Macosx 11.6, the caption is not centered: TeXlive 2021 output

However, running with TeXlive 2019 on Ubuntu 20.04, the centering is correct: TeXlive 2019 output I have checked that the part of amsart.cls concerned with figure captions has not changed between these versions. Also, it doesn't make any difference whether latex or pdflatex is used. The problem only occurs for captions that fit on one line.

These are the only two versions of TeXlive that I have easy access to.

5
  • nice test file, thanks Sep 18, 2021 at 8:28
  • this is now fixed in the public latex-dev release Sep 21, 2021 at 7:37
  • @DavidCarlisle Splendid! I am impressed. Sep 21, 2021 at 11:50
  • 1
    Setting \captionindent=0pt was a reasonable temporary work around for me pending the fix. Sep 27, 2021 at 16:32
  • @AndrewSwann Yes, except that if the caption needs more than one line, the appearance changes. So this workaround needs to be applied only to short captions. Sep 28, 2021 at 1:05

1 Answer 1

8

The original file works without error in LaTeX releases from

LaTeX2e <2021-11-15> pre-release-2 (develop 2021-9-20 branch)

Original answer

The class needs to be updated for the 2021 latex release, an extra unkern is needed

update actually we will probably adjust things in the latex format so the following patch will not be necessary after the next latex release https://github.com/latex3/latex2e/pull/671

enter image description here

\documentclass{amsart}
\makeatletter
\long\def\@makecaption#1#2{%
  \setbox\@tempboxa\vbox{\color@setgroup
    \advance\hsize-2\captionindent\noindent
    \@captionfont\@captionheadfont#1\@xp\@ifnotempty\@xp
        {\@cdr#2\@nil}{.\@captionfont\upshape\enspace#2}%
    \unskip\kern-2\captionindent\par
    \global\setbox\@ne\lastbox\color@endgroup}%
  \ifhbox\@ne % the normal case
    \setbox\@ne\hbox{\unhbox\@ne\unskip\unskip\unpenalty\unkern\unkern}%
                                                               %%%%%%% extra unkern
  \fi
  \ifdim\wd\@tempboxa=\z@ % this means caption will fit on one line
    \setbox\@ne\hbox to\columnwidth{\hss\kern-2\captionindent\box\@ne\hss}%
  \else % tempboxa contained more than one line
    \setbox\@ne\vbox{\unvbox\@tempboxa\parskip\z@skip
        \noindent\unhbox\@ne\advance\hsize-2\captionindent\par}%
  \fi
  \ifnum\@tempcnta<64 % if the float IS a figure...
    \addvspace\abovecaptionskip
    \hbox to\hsize{\kern\captionindent\box\@ne\hss}%
  \else % if the float IS NOT a figure...
    \hbox to\hsize{\kern\captionindent\box\@ne\hss}%
    \nobreak
    \vskip\belowcaptionskip
  \fi
\relax
}
\makeatother
\begin{document}

\hbox to\hsize{X\hfil \TeX{Live} 2021 on Mac\hfil X}

\begin{figure}[h]
\hbox to\hsize{X\hfil X\hfil X}
\caption{XXXXX}
\end{figure}
\end{document}
3
  • Perfect answer, thanks. As of today, that hasn't appeared in the TeXlive package update stream. Do you know if it is in the pipeline, or should I report it somewhere? Sep 18, 2021 at 9:23
  • @BrendanMcKay no I meant it would need to be reported, but don't yet, just looking with the rest of the latex project team if we can tweak the latex change (related to the new paragraph hooks) so the class isn't affected. We'll ping the ams if needed. Sep 18, 2021 at 9:49
  • @BrendanMcKay See note and link I just added to this answer Sep 18, 2021 at 22:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.