1

I have the following MWE.

\documentclass[12pt, a4paper]{report}
\usepackage[hidelinks]{hyperref}
\usepackage[all]{hypcap}
\begin{document}
As seen in Table \ref{table1} and \ref{table2}.
\begin{table}
\centering
\begin{tabular}{ l | c || r }
  \hline                        
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9 \\
  \hline  
\end{tabular}
\caption{Table 1}
\label{table1}
\begin{tabular}{ l | c || r }
  \hline                        
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9 \\
  \hline  
\end{tabular}
\caption{Table 2}
\label{table2}
\end{table}
\end{document}

I have two 'tabulars' defined within a table, this a requirement for me. I'm using the hyperref package to have clickable links to the tables. I'm also using \usepackage[all]{hypcap} in the premable so that on clicking the links, the page scrolls to the top of the table instead of the caption. However, on clicking the link of Table 2, the page scrolls to the caption. I'm suspecting this is happening because I have two tables grouped together.

How could I go about this? I accept any workarounds as long as the tables would remain grouped together. I'd like to use this for figures as well.

Thanks,

4

The first \capstart is automatically set in table by \usepackage[all]{hypcap}. But the second \capstart for the second \caption needs to be placed manually:

\documentclass[12pt, a4paper]{report}
\usepackage[hidelinks]{hyperref}
\usepackage[all]{hypcap}

\begin{document}
  As seen in Table \ref{table1} and \ref{table2}.
  \begin{table}
    \centering
    \begin{tabular}{ l | c || r }
      \hline
      1 & 2 & 3 \\
      4 & 5 & 6 \\
      7 & 8 & 9 \\
      \hline
    \end{tabular}
    \caption{Table 1}
    \label{table1}

    \bigskip
    \capstart
    \begin{tabular}{ l | c || r }
      \hline
      1 & 2 & 3 \\
      4 & 5 & 6 \\
      7 & 8 & 9 \\
      \hline
    \end{tabular}
    \caption{Table 2}
    \label{table2}
  \end{table}
\end{document}

Result

(Image with \usepackage[a6paper]{geometry} for smaller image.)

0

This worked for me, but it violates your assumption to have table within the table, yet the result is the same I suppose:

\documentclass[12pt, a4paper]{report}
\usepackage[hidelinks]{hyperref}
\usepackage[all]{hypcap}
\begin{document}
As seen in Table \ref{table1} and \ref{table2}.

\begin{table}
\centering
\begin{tabular}{ l | c || r }
 \hline                        
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9 \\
 \hline  
 \end{tabular}
\caption{Table 1}
\label{table1}
\end{table}

\begin{table}
\centering
\begin{tabular}{ l | c || r }
  \hline                        
  1 & 2 & 3 \\
  4 & 5 & 6 \\
  7 & 8 & 9 \\
  \hline  
 \end{tabular}

\caption{Table 2}
\label{table2}
\end{table}
\end{document}

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.