0
% !TeX TS-program = pdflatex
% !TeX encoding = UTF-8
\documentclass{article}
\usepackage{float}
\usepackage{graphicx}
\counterwithin{figure}{section}
\usepackage{hyperref}
%\counterwithin{figure}{section}
%\usepackage[all]{hypcap}
\begin{document}

\section{one}
 \begin{figure}[H]
  \centerline{\includegraphics[width=10cm]{example-image}}
  \caption{example-image}
 \end{figure}


\clearpage
\section{two}
 \begin{figure}[htb]
  \centerline{\includegraphics[width=11cm]{example-image-a}}
  \caption{example-image-a}
 \end{figure}

\end{document}

(pdftex.def) Requested size: 312.9803pt x 234.74237pt.
pdfTeX warning (ext4): destination with the same identifier (name{figure.1}) ha
s been already used, duplicate ignored
to be read again>
\relax
l.23 \caption{example-image-a}

I've read

and the Problem persist

2

hyperref patches \counterwithin but you use it before hyperref got the change of patching it. So use \counterwithin after loading the hyperref package and the problem should be gone.

The answer from Ulrike is just a work-around, trying to correct the damage done by the wrong package load and usage order. IMHO this is the wrong approach.

See also https://texfaq.org/FAQ-hyperdupdest

"In most cases, therefore, you should load your package before you load hyperref, and hyperref will patch things up so that they work, so you can utilise your (patched) package after loading both"

Means in this case: Load the package which provides \counterwithin first (not necessary here since it is offered by recent LaTeX kernels), load hyperref afterwards (so it can patch \counterwithin, and then (and only then) use \counterwithin.

|improve this answer|||||
1

Redefine \theHfigure so that it gives an unique identifier for the destination anchor:

\documentclass{article}
\usepackage{float}
\usepackage{graphicx}
\counterwithin{figure}{section}
\usepackage{hyperref}
%\counterwithin{figure}{section}
%\usepackage[all]{hypcap}
\renewcommand\theHfigure{\thesection.\arabic{figure}}
\begin{document}

\section{one}
 \begin{figure}[H]
  \centerline{\includegraphics[width=10cm]{example-image}}
  \caption{example-image}
 \end{figure}


\clearpage
\section{two}
 \begin{figure}[htb]
  \centerline{\includegraphics[width=11cm]{example-image-a}}
  \caption{example-image-a}
 \end{figure}

\end{document}
|improve this answer|||||
0
\counterwithin{figure}{section}
\usepackage[all]{hypcap}

in the preamble after the hyperref-package. In this case \counterwithin{figure}{section} aswell \usepackage[all]{hypcap} is enough, but sometimes you need both, also \usepackage{caption} often helps.

This question uses

|improve this answer|||||

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.