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

9
  • How do I change the color of the word "Table" from black to blue when I cross-refer this table. Same for the figures cross-reference. Thank you in advance
    – Prakash
    Dec 18, 2017 at 5:08
  • Please put your question in the question - comments are subject to deletion. Have you looked at hyperref's manual? You just pick the relevant option - just as you have for citations. What's the problem exactly? You never really say.
    – cfr
    Dec 18, 2017 at 5:15
  • Thank for the quick response. When I cross-refer the Tables and the Figures, I would like to get Table.1 (In blue color) and Fig.1 (In blue color). Now I am getting only the number in blue but not the Table.1 and Fig.1. Thank you.
    – Prakash
    Dec 18, 2017 at 5:20
  • Dear @koleygr, I did not get any answers before for my questions on cross-reference and citation. I would appreciate anyone answered. I will definitely accept answers. Thank you. How do I get colored cross-reference of Tables and Figures?
    – Prakash
    Dec 18, 2017 at 5:47
  • @Prakash Did you checked my answer? I didn't checked your questions before and I am going to delete my above comment. The only open question I see with non-accepted answer by you is this : tex.stackexchange.com/questions/383655/…... The others are closed or unanswered... But it is not big deal... Deleting my previous comment...(Sorry!... Just show too many white questions in your profile)
    – koleygr
    Dec 18, 2017 at 6:04

2 Answers 2

1

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)

0
3

Since you're already loading the hyperref package, all you need to do is (a) to load the cleveref package with the options nameinlink and noabbrev and (b) to use either \cref or \Cref (the latter if the first character of the label should be upper-cased) instead of \ref.

That way, not only will the "labels" ("Figure" and "Table") be rendered in blue, the labels will also be part of the hyperlink, i.e., of the string that readers can click on in order to jump to the respective target.

enter image description here

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

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.