\documentclass[1p]{elsarticle}
\usepackage{lineno}
\modulolinenumbers[5]
\journal{Journal of \LaTeX\ Templates}
\usepackage{multirow}
\usepackage{hyperref}
\hypersetup{
colorlinks = true,
citecolor = blue
}
\begin{document}
\section{Introduction}
%\begin{table}[H]
\begin{table*}
\caption{Comparison} \label{accuracy_static_defl}
\centering
\begin{tabular}{c c c c c c}
\hline
\multirow{3}{*}{Smith($\mu$)} &\multicolumn{2}{c}{Numerical solution}\\ \cline{2-3}&Deflection($\mu$)&error\\ \cline{2-3} \cline{4-5}
&App 1 &App2\\
\hline
100.34500&100.345098&100.0286& \\
\hline
\end{tabular}
%\end{table}
\end{table*}
Table.\ref{accuracy_static_defl}
\end{document}
答案1
不使用 cleveref 进行编辑(重新定义\ref
但使用xstring
):
\documentclass[1p]{elsarticle}
\usepackage{graphicx}
\usepackage{lineno}
\usepackage{xcolor}
\modulolinenumbers[5]
\journal{Journal of \LaTeX\ Templates}
\usepackage{multirow}
\usepackage{xstring}
\usepackage{hyperref}
\hypersetup{
colorlinks = true,
citecolor = blue,
linkcolor=blue %%%ADDED for the links (needed in e.g. article)
}
%%%ADDED FOR THE ANSWER
\usepackage{xstring}
\makeatletter
\AtBeginDocument{
\let\oldref\ref
\renewcommand{\ref}[1]{\IfBeginWith{#1}{fig:}%
{{\color{blue}Figure~\oldref{#1}}}%
{\IfBeginWith{#1}{tab:}{{\color{blue}Table~\oldref{#1}}}{Unsupported ref start}}}%
}
\makeatother
\begin{document}
\section{Introduction}
\begin{table*}
\caption{Comparison} \label{tab:accuracy_static_defl}
\centering
\begin{tabular}{c c c c c c}
\hline
\multirow{3}{*}{Smith($\mu$)} &\multicolumn{2}{c}{Numerical solution}\\ \cline{2-3}&Deflection($\mu$)&error\\ \cline{2-3} \cline{4-5}
&App 1 &App2\\
\hline
100.34500&100.345098&100.0286& \\
\hline
\end{tabular}
\end{table*}
\begin{figure}
\caption{Comparison} \label{fig:accuracy_static_defl}
\includegraphics[width=0.6\textwidth]{example-image-a}
\centering
\end{figure}
In the \ref{fig:accuracy_static_defl} or the \ref{tab:accuracy_static_defl}...
输出:
cleveref 的旧答案:
由于我没有 cls 文件,因此这里有一个答案供您检查:
\documentclass[1p]{elsarticle}
\usepackage{lineno}
\modulolinenumbers[5]
\journal{Journal of \LaTeX\ Templates}
\usepackage{multirow}
\usepackage{hyperref}
\hypersetup{
colorlinks = true,
citecolor = blue,
linkcolor=blue %%%ADDED for the links (needed in e.g. article)
}
%%%ADDED FOR THE ANSWER
\usepackage{cleveref}
\let\oldcref\cref
\def\cref#1{\color{blue}\oldcref{#1}}
\begin{document}
\section{Introduction}
%\begin{table}[H]
\begin{table*}
\caption{Comparison} \label{accuracy_static_defl}
\centering
\begin{tabular}{c c c c c c}
\hline
\multirow{3}{*}{Smith($\mu$)} &\multicolumn{2}{c}{Numerical solution}\\ \cline{2-3}&Deflection($\mu$)&error\\ \cline{2-3} \cline{4-5}
&App 1 &App2\\
\hline
100.34500&100.345098&100.0286& \\
\hline
\end{tabular}
%\end{table}
\end{table*}
In the \cref{accuracy_static_defl}..
\end{document}
这个想法是使用cleveref
提供命令的包\cref
。我重新定义了这个命令,用蓝色打印所有内容。(颜色链接)
答案2
由于您已经加载了hyperref
包,您需要做的就是(a)使用cleveref
选项nameinlink
和加载包,noabbrev
以及(b)使用\cref
或\Cref
(如果标签的第一个字符应该大写,则使用后者)而不是\ref
。
这样,不仅“标签”(“图形”和“表格”)将呈现为蓝色,而且标签还将成为超链接的一部分,即读者可以点击以跳转到相应目标的字符串。
\documentclass[1p]{elsarticle}
\usepackage{hyperref}
\hypersetup{colorlinks = true, allcolors = blue}
\usepackage[nameinlink,noabbrev]{cleveref} % <-- new
\begin{document}
%% Create dummy table and figure environments:
\begin{table}
\caption{Comparison} \label{accuracy_static_defl}
\end{table}
\begin{figure}[h!]
\caption{Hello World} \label{hello}
\end{figure}
\Cref{accuracy_static_defl} shows that \dots\
As was shown in \cref{hello}, \dots
\end{document}