[Tex/LaTex] Elsarticle cross-reference of Table and Figure in blue color

cross-referencingelsarticle

\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}

enter image description here

Best Answer

Edit without cleveref (redefining \ref but using 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}...

Output:

enter image description here

Old Answer with cleveref:

Here is an answer for you to check because I have not the cls file:

\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}

The idea is to use cleveref package that provides \cref command. And I redefined this command to print everything in blue. (The colorlinks)