hyperref 与 \addtocounter 冲突

hyperref 与 \addtocounter 冲突

由于某些原因,我需要借助该capt-of包来定义表格前的标题。当我尝试使用该hyperref包时,发生了冲突\addtocounter并发出以下警告(但在生成的 PDF 文件中没有观察到明显问题):

pdfTex warning (ext4): destination with the same identifier (name{table.2}) has been already used, duplicate ignored.

我的示例代码如下:

\documentclass[a4paper,pra,aps,11pt]{revtex4-2}

\usepackage{float}
\usepackage{hyperref}
\usepackage{amsmath,amssymb}
\usepackage[english]{babel}
\usepackage{longtable}
\usepackage{capt-of}

\begin{document}

\captionof{table}{test A}
\begin{longtable}{l}
\end{longtable}
\addtocounter{table}{-1}
\makeatletter\def\@currentlabel{\thetable}\label{table:testA}

\captionof{table}{test B}
\begin{longtable}{l}
\end{longtable}
\addtocounter{table}{-1}
\makeatletter\def\@currentlabel{\thetable}\label{table:testB}

table~\ref{table:testA} and table~\ref{table:testB}

\end{document}

您能帮我避免这个警告吗?请不要建议我删除该capt-of软件包(...)。

答案1

使用附加计数器:

\documentclass[a4paper,pra,aps,11pt]{revtex4-2}

\usepackage{float}
\usepackage{hyperref}
\usepackage{amsmath,amssymb}
\usepackage[english]{babel}
\usepackage{longtable}
\usepackage{capt-of}
\newcounter{abstable}
\renewcommand\theHtable{\arabic{abstable}.\thetable}
\begin{document}

\captionof{table}{test A}
\begin{longtable}{l}
\end{longtable}
\stepcounter{abstable}\addtocounter{table}{-1}
\makeatletter\def\@currentlabel{\thetable}\label{table:testA}

\captionof{table}{test B}
\begin{longtable}{l}
\end{longtable}
\stepcounter{abstable}\addtocounter{table}{-1}
\makeatletter\def\@currentlabel{\thetable}\label{table:testB}

table~\ref{table:testA} and table~\ref{table:testB}

\end{document}

相关内容