Main question: How can I change the text that prints when I cross-reference an object in my text? I'd like to get a \renewcommand
that works for tables only and another one that works for sentences under \begin{enumerate}
. A thorough explanation of my issue, my code, and the output images for the corresponding code are located below.
Any help is much appreciated!
When I cross-reference an object, like a table, in LaTeX using the hyperref
package, I would like to have the name of the object as part of the link. For example, in the code below we see that the first example of \ref{label}
does not mention the name of the object. The second example names it only if I add it manually, but it's not part of the link. And the third example makes the whole phrase a link, but the text of the link needs to be modified manually. (more below).
\documentclass{article}
\usepackage{caption}
\usepackage[colorlinks]{hyperref}
\begin{document}
\begin{table}
\centering
\caption{Table with text}\vspace{-1em}\label{T1}
\begin{tabular}{ | c | c | c | }
\hline
Column1 & Column2 & Column3\\
\hline
\hline
C1-text1 & C2-text1 & C3-text1\\
\hline
C1-text2 & C2-text2 & C3-text2\\
\hline
C1-text3 & C2-text3 & C3-text3\\
\hline
\end{tabular}
\end{table}
We can see in \ref{T1} that...
We can see in Table \ref{T1}
We can see in \hyperref[T1]{Table 1} that...
\end{document}
However, the third option is not one that I want to stick to, because it brings other issues down the road. For instance, if I add another table before this table, I need to make sure to go back and modify the link-text for each item, or else I end up with a wrongly labeled table in my document. For example:
\documentclass{article}
\usepackage{float} %To make sure the tables display in order.
\usepackage{caption}
\usepackage[colorlinks]{hyperref}
\begin{document}
\begin{table}
\caption{Other table}\label{added table}
\centering
\begin{tabular}{c c}
\hline
C1 & C2\\
\hline
T1 & T2\\
\hline
\end{tabular}
\end{table}
We can see in \ref{added table} that
\begin{table}[H]
\centering
\caption{Table with text}\vspace{-1em}\label{T1}
\begin{tabular}{ | c | c | c | }
\hline
Column1 & Column2 & Column3\\
\hline
\hline
C1-text1 & C2-text1 & C3-text1\\
\hline
C1-text2 & C2-text2 & C3-text2\\
\hline
C1-text3 & C2-text3 & C3-text3\\
\hline
\end{tabular}
\end{table}
We can see in \ref{T1} that...
We can see in Table \ref{T1}
We can see in \hyperref[T1]{Table 1} that...
\end{document}
My question is: how can I provide a \renewcommand
so that I can modify the text that is printed when I cross-reference an object in the body of my document? I'd also like for the command to make a distinction between tables and other objects such as sentences with the \begin{enumerate}
or \begin{itemize}
commands. I don't want to end up calling my sentences Table X
nor do I want the enumeration between tables and sentences to get mixed up.
On a side note, do people recommend using the \centering
command or the \begin{center}
environment for tables? And why?