0

This is a question about what's happening under the hood, since I already know some ways to get my desired output. My question is what is the reason why the combination of numberwithin/hyperref behaves differently for equations than for tables. Namely, the following code has the problem that the hyperlink to Table 3.1 actually points to Table 2.1. But the hyperlink to equation 3.1 correctly points to equation 3.1. I'm aware that this can be fixed by moving the \numberwithin commands to after the \usepackage{hyperref} (or via other methods). But I don't understand why the following code behaves differently for equations versus for tables, and I wonder whether this is an instance of some more general thing that I would benefit from knowing. Is there some general way in which (La)TeX handles equations differently from tables?

\documentclass{amsart}
\usepackage{amsmath}

\numberwithin{equation}{section}
\numberwithin{table}{section}

\usepackage[colorlinks]{hyperref}

\begin{document}

\section{Introduction}

Cite equations \eqref{eq1} and \eqref{eq2}, and Tables \ref{table1} and \ref{table2}.

\newpage

\section{Body}

\begin{equation}\label{eq1}
2+2=4
\end{equation}

\begin{table}[htbp]
\caption{}
\label{table1}
\begin{tabular}{|c|c|}
\hline
1&2 \\ \hline
3&4 \\ \hline
\end{tabular}
\end{table}

\newpage
\section{Conclusion}

\begin{equation}\label{eq2}
4+4=8
\end{equation}

\begin{table}[htbp]
\caption{}
\label{table2}
\begin{tabular}{|c|c|}
\hline
5&6 \\ \hline
7&8 \\ \hline
\end{tabular}
\end{table}

\end{document}

1 Answer 1

2

You get a warning from pdftex about duplicate destination names:

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

The cause is that hyperref assumes tables with unique numbers and creates for both the destination table.1.

If you move the \numberwithin{table}{section} behind hyperref, hyperref can kick in and adapt the destination name too (it will then use table.1.1 and table.2.1 etc).

The alternative is to adjust the destination name manually:

\renewcommand\theHtable{\thetable}

equations are different as at some time in history hyperref decided that it is safer to add the section number anyway. So it contains the definition

\providecommand\theHequation{\theHsection.\arabic{equation}
1
  • Thanks! To me it seems odd that hyperref does something different for equations than for tables, but anyway it's comforting to know that the issue I observed comes from that package, rather than from some more fundamental TeX issue I didn't know. Commented Mar 3 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .