在 tabularray 中使用时,交叉引用的自定义计数器不正确

在 tabularray 中使用时,交叉引用的自定义计数器不正确

我想分享一些东西。我创建了一个自定义计数器来交叉引用子图。

tblr由于某种原因,如果我在环境(包中定义的环境)内使用它,计数器会出错tabularray。我测试了类似的方法tabular,后者按预期工作。

我仍在使用 TexLive 2021,并获取最新更新:

Version 1.13.2 (TeX Live 2021)  (format=lualatex 2022.3.25)  25 MAR 2022 13:25
Package: tabularray 2022-03-01 v2022A Typeset tabulars and arrays with LaTeX3
Package: cleveref 2018/03/27 v0.21.4 Intelligent cross-referencing

妇女权利委员会:

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{tabularray}
    \UseTblrLibrary{booktabs}
\usepackage{cleveref}

\newcounter{mycustomcounter}
\renewcommand\themycustomcounter{(\alph{mycustomcounter})}
\crefname{mycustomcounter}{subfigure}{subfigures}
\Crefname{mycustomcounter}{Subfigure}{Subfigures}
\crefformat{mycustomcounter}{#2subfigure~#1#3}
\Crefformat{mycustomcounter}{#2Subfigure~#1#3}


\begin{document}

\begin{figure}[htbp]
    \setcounter{mycustomcounter}{0}
    \centering
    \begin{tblr}{
        width=0.9\textwidth,
        colspec={X[c] X[c]},
    }
        \includegraphics[width=0.4\textwidth]{example-image-a}
        &
        \includegraphics[width=0.4\textwidth]{example-image-b}
        \\
        \refstepcounter{mycustomcounter}
        \label{fig:example1}
        \themycustomcounter
        &
        \refstepcounter{mycustomcounter}
        \label{fig:example2}
        \themycustomcounter
    \end{tblr}
\end{figure}

\begin{figure}[htbp]
    \setcounter{mycustomcounter}{0}
    \centering
    \begin{tabular}{cc}
        \includegraphics[width=0.4\textwidth]{example-image-a}
        &
        \includegraphics[width=0.4\textwidth]{example-image-b}
        \\
        \refstepcounter{mycustomcounter}
        \label{fig:example3}
        \themycustomcounter
        &
        \refstepcounter{mycustomcounter}
        \label{fig:example4}
        \themycustomcounter
    \end{tabular}
\end{figure}

References to subfigures: \labelcref{fig:example1}, \labelcref{fig:example2}, \labelcref{fig:example3}, \labelcref{fig:example4}.

\end{document}

在此处输入图片描述

答案1

\UseTblrLibrary{counter}我不明白为什么,但这是记录在案的行为。手册上说“如果您想修改表格中的某些 LaTeX 计数器,则需要使用 加载计数器库tabularray。”事实上,有了它,它就能按预期工作。

\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{tabularray}
\UseTblrLibrary{booktabs}
\UseTblrLibrary{counter}
\usepackage{cleveref}

\newcounter{mycustomcounter}
\renewcommand\themycustomcounter{(\alph{mycustomcounter})}
\crefname{mycustomcounter}{subfigure}{subfigures}
\Crefname{mycustomcounter}{Subfigure}{Subfigures}
\crefformat{mycustomcounter}{#2subfigure~#1#3}
\Crefformat{mycustomcounter}{#2Subfigure~#1#3}


\begin{document}

\begin{table}[htbp]
    \setcounter{mycustomcounter}{0}
    \centering
    \begin{tblr}{
        width=0.9\textwidth,
        colspec={X[c] X[c]},
    }
        \includegraphics[width=0.4\textwidth]{example-image-a}
        &
        \includegraphics[width=0.4\textwidth]{example-image-b}
        \\
        \refstepcounter{mycustomcounter}
        \label{fig:example1}
        \themycustomcounter
        &
        \refstepcounter{mycustomcounter}
        \label{fig:example2}
        \themycustomcounter
    \end{tblr}
\end{table}

\begin{table}[htbp]
    \setcounter{mycustomcounter}{0}
    \centering
    \begin{tabular}{cc}
        \includegraphics[width=0.4\textwidth]{example-image-a}
        &
        \includegraphics[width=0.4\textwidth]{example-image-b}
        \\
        \refstepcounter{mycustomcounter}
        \label{fig:example3}
        \themycustomcounter
        &
        \refstepcounter{mycustomcounter}
        \label{fig:example4}
        \themycustomcounter
    \end{tabular}
\end{table}


References to subfigures: \labelcref{fig:example1}, \labelcref{fig:example2}, \labelcref{fig:example3}, \labelcref{fig:example4}.

\end{document}

在此处输入图片描述

相关内容