0

I renewcommand the numbering for my tables and figures in my appendix. But when I use the ref command in the text, it doesnt jump to the right figure in the appendix. For example I have figure 1 in my mean section and figure A.Abb.1 in my appendix and I want to use \ref{test123} in the mean section it jumps to figure 1 in the mean section and not to figure A.Abb.1 in the appendix. How can I fix it?

       \documentclass[a4paper, 12pt]{article}
        \usepackage{hyperref}
        \usepackage{amsmath,amssymb,slashbox,graphicx}
    \usepackage{float}
        \begin{document}

\begin{figure}[h]
    \includegraphics[width=1\textwidth,height=180px]{test1234}
    \caption{test1234}\label{test1234}
\end{figure}

blabla \ref{test1234}
       blabla \ref{test123}

        \section*{Appendix}

        \setcounter{table}{0}
        \renewcommand{\thetable}{A.Tab.\arabic{table}}
        \setcounter{figure}{0}
        \renewcommand{\thefigure}{A.Abb.\arabic{figure}}
        \setcounter{figure}{0}

        \begin{figure}[H]
            \includegraphics[width=1.0\textwidth]{test}
            \caption{test}\label{test123}
        \end{figure}



        \end{document}
florian
  • 31
  • Your MWE does not compile. – samcarter_is_at_topanswers.xyz Jul 20 '18 at 15:32
  • Thanks for the edit. Your MWE works fine for me and the link jumps to Figure A.Abb.1 – samcarter_is_at_topanswers.xyz Jul 20 '18 at 15:46
  • maybe its smarter if I put two figures for the example ;-) . Does it work now? – florian Jul 20 '18 at 15:50
  • I don't have an image test. When using example-image-a instead, the hyperlink does indeed lead to Figure A.Abb.1, but the .log-file contains the warning pdfTeX warning (ext4): destination with the same identifier (name{figure.1}) has been already used, duplicate ignored. I get this warning only when the float package is loaded. Maybe I've an obsolete version thereof, maybe there's a bug in that package. – Ulrich Diez Jul 20 '18 at 15:57

1 Answers1

3

The hyperref package does automatically create names for anchors of hyperlinks. For creating these names it defines for each ⟨counter⟩ a macro \theH⟨counter⟩.

When resetting a ⟨counter⟩ to 0 or to whatsoever previous value, uniqueness of anchor-names is not ensured any more unless you also adjust \theH⟨counter⟩:

\documentclass[a4paper, 12pt]{article}
\usepackage{hyperref}
\usepackage{amsmath,amssymb,slashbox,graphicx}
\usepackage{float}
\begin{document}

\begin{figure}[h]
  \includegraphics[width=1\textwidth,height=180px]{example-image-a}
  \caption{test1234}\label{test1234}
\end{figure}

blabla \ref{test1234}
blabla \ref{test123}

\section*{Appendix}

\renewcommand{\thetable}{A.Tab.\arabic{table}}
\renewcommand{\thefigure}{A.Abb.\arabic{figure}}
\renewcommand{\theHtable}{A.Tab.\arabic{table}}%<---!!!!---
\renewcommand{\theHfigure}{A.Abb.\arabic{figure}}%<---!!!!---
\setcounter{table}{0}
\setcounter{figure}{0}

\begin{figure}[H]
  \includegraphics[width=1.0\textwidth]{example-image-b}
  \caption{test}\label{test123}
\end{figure}

\end{document}

With this adjustment, hyperlinks lead to the right places.

But the issue mentioned in my comment to your question, i.e., the issue about pdfTeX warning (ext4): destination with the same identifier (name{...}) has been already used, duplicate ignored. in the .log-file is still not resolved. That warning only occurs when the float package is loaded. I suppose it is a bug in that package which has to do with its way of using \AtBeginShipoutBox.

Ulrich Diez
  • 28,770