[Tex/LaTex] pdfTeX warning (ext4): destination with the same identifier (name{figure.1}) has been already used, duplicate ignored

captionscjkhyperrefpdftexwarnings

I've tried to make bilingual caption with package "ccaption" and compiled it with pdfLaTeX.

It works fine but with a warning:

pdfTeX warning (ext4): destination with the same identifier (name{figure.1}) has been already used, duplicate ignored.

Here is a mini example:

\documentclass[UTF8]{ctexart}                 
\usepackage{graphicx}               
\usepackage{ccaption}
\usepackage{hyperref}

\begin{document}
Figure \ref{fig1}
\begin{figure}
\bicaption[fig1]{}{中文标题}{Fig.}{English caption}
\end{figure}
\end{document}

Sorry for the inconvenience if you don't have package ctex which defines a documents class ctexart for typesetting Chinese. You can replace the documentclass with article and the warning it still there.

Best Answer

ccaption uses an elementary (and mostly feasible) way of producing duplicate captions for the same float. The main function at play here is \contcaption:

\newcommand{\contcaption}{%
  \addtocounter{\@captype}{\m@ne}%
  \refstepcounter{\@captype}%
  \@contcaption\@captype}

It steps the regular float counter back by one, sets a reference and then continues a call to set the actual caption text. On the .aux-file side, this leads to two cross-reference entries with the same hyperlink anchor name... something that hyperref doesn't enjoy. True, without hyperref, this problem won't be noticeable.

A way around this is to use an alias counter, provided by the aliascnt package, and using it as part of \contcaption:

enter image description here

\documentclass[UTF8]{ctexart}
\usepackage{aliascnt,ccaption}% http://ctan.org/pkg/{aliascnt,ccaption}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref

\newaliascnt{figurealt}{figure}% New alias counter for figure float
\aliascntresetthe{figurealt}
\makeatletter
\renewcommand{\contcaption}{%
  \expandafter\addtocounter\expandafter{\@captype alt}{\m@ne}% Step alias cntr back
  \expandafter\refstepcounter\expandafter{\@captype alt}% Make reference
  \@contcaption\@captype}
\makeatother
\begin{document}
Figures~\ref{fig1} and~\ref{fig2}.
\begin{figure}
\bicaption[fig1]{}{abc}{Fig.}{English caption}
\end{figure}
\begin{figure}
\bicaption[fig2]{}{xyz}{Fig.}{English caption}
\end{figure}
\end{document}

The above MWE provides the alias figurealt which should work in tandem with figure, using it as the replacement reference for the second (continued) caption rather than the traditional float counter.

A similar alias can be created for other floats (like table, using tablealt).