我可以使整个“表1”可单击以作为Latex的参考吗?

时间:2018-07-07 17:27:24

标签: latex

在我的文档中,我正在使用label函数来标记表格和图形:

\label{}

然后,我使用\ref{}函数来引用表格或图形。在我的文字中。

我遇到的问题是在我的文字中这样写:

As can be seen in Table \ref{table1}.

它将输出我的文本为:

As can be seen in Table 1.

但是,只有数字“ 1”是可单击的并指向表格。我也希望“表格”部分也是可点击的,因此您可以单击“表格1”的任何部分并向上引用该表格。

我尝试使用不同的方法,先使用\phantomsection\label{},然后使用\hyperref[]{},但这不会动态输出表格或图形编号。

1 个答案:

答案 0 :(得分:4)

使用\autoref

\autoref根据类型创建带有文本的引用。

一张图片会讲出超过一千个单词:

enter image description here

示例代码:

\documentclass[a4paper]{article}

\usepackage[english]{babel}

\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}

\begin{document}

\textbackslash ref to the Figure \ref{fig:example}

\textbackslash autoref to the  \autoref{fig:example}

\textbackslash nameref to the figure \nameref{fig:example}

\begin{figure}
\centering
\includegraphics[width=0.3\textwidth]{example-image-a}
\caption{\label{fig:example}Example image}
\end{figure}


\end{document}

例如,将\autoref插入的文本更改为一张桌子:

\renewcommand{\tableautorefname}{bettertablename}

有关所有选项,请参见hyperref手册。