I'm trying to create a two-way link between tables/figures and the list of all tables/figures that I manually created. I.e., each item in the list of tables should link to a table, and clicking on the table caption should link back to the reference.
When linking the table/figure, I would like to use the table/figure name, not its number, as is possible with \namref.
I found a solution that works when using \ref, but when I try to insert \nameref inside of the hyperlink, it doesn't work anymore. I tried inserting \phantomsection before the table label and removing the link using \nameref* to avoid clashes between the links, but that didn't help. I also tried various other link setups, such as with cleverref, but didn't succeed yet.
So the following code doesn't work, but if I replaced \nameref with \ref, it would work.
But I want the table name in the reference (without manually typing it out because I have hundreds of tables), and not the table number.
\documentclass{article}
\usepackage{hyperref}
\newcommand{\mylabel}[2]{%
\hyperlink{back:#1}{\hypertarget{#1}{#2}}
}
\newcommand{\myref}[2]{%
\hyperlink{#1}{\hypertarget{back:#1}{#2}}
}
\begin{document}
\begin{enumerate}
\item \myref{link}{\nameref{testtab}}
\end{enumerate}
\newpage
\begin{table}
\caption{\mylabel{link}{My Table}}\label{testtab}
\centering
\begin{tabular}[t]{rr}
\toprule
\textbf{Col A} & \textbf{Col B} \
\midrule
1 & A \
2 & B \
\end{tabular}
\end{table}
\end{document}
Weirdly, with \nameref, the output shows two links, with one on top that seems to link to itself, and the other being only clickable at the very right and linking correctly to the table (see screenshot).
How could I set this up correctly?
Thank you so much in advance for any tips, I'm new to StackExchange and relatively new to LaTeX, so any support is highly appreciated.
Edit: The list(s) of tables/figures I want to create needs to be highly customizable (contain both linked and non-linked entries, multiple depths, be split into multiple parts, contain tables and figures), such that \listoftables doesn't seem to be an alternative way to solve the issue

booktabspackage. – daleif Aug 08 '23 at 07:36