7

enter image description here

I'm preparing my manuscript for a journal in which figures are in the following clickable format like, for exapmle, "Fig. 1", "Figs. 2 and 3" and "Figs. 4-6". I'm trying to use the same environment of \hyperref as given in the existing code provided by Heiko Oberdiek, but not getting the required format. Please have a look on the attached screenshot for figure referencing style. The MWE is copied from existing code,

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{todonotes}
\usepackage{hyperref}

\newcommand*{\figref}[2][]{%
\hyperref[{fig:#2}]{%
Fig.~\ref*{fig:#2}%
\ifx\\#1\\%
\else
\,#1%
\fi
  }%
}
\begin{document}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 1.}
\label{fig:missing Figure1}
\end{figure}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 2.}
\label{fig:missing Figure2}
\end{figure}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 3.}
\label{fig:missing Figure3}
\end{figure}

The single figure should be like that \figref{missing Figure1}.
And two figures be like that \figref{missing Figure1} and \figref{missing Figure2}, 
moreover the combination of three figures like tha \figref{missing Figure1, 
missing Figure2,missing Figure3} as you can see in the attached journal's 
screenshot.

\end{document}
Mico
  • 506,678
kamran
  • 191
  • 1
    Quick solution without getting more information: \usepackage[colorlinks,linkcolor=blue]{hyperref} followed by \usepackage[nameinlink,capitalise]{cleveref} and use \cref instead of \ref etc. – sodd May 25 '17 at 15:47
  • @hooy, Nice reply, it works, but I want get "Figs.1-3" instead of "Figs.1 to 3". Similarly "Figs.1 and 2", in which "and" should also be clickable. – kamran May 25 '17 at 16:08
  • @kamran See my answer below. Also, it does not really make sense to have "and" clickable. Which of the figures should this link to? I'd keep "and" out from any links, just to avoid confusion. – sodd May 25 '17 at 16:15
  • @hooy, Thanks for your answer below, It seems to be an excellent, but it is a journals' requirement that's why I've attached a screenshot in my question. – kamran May 25 '17 at 16:26
  • The screenshot you've posted practices weirdly inconsistent highlighting of the hyperlinks: "Fig", "Figs.", and "Table" would all appear to be part of the respective hyperlinks, where "Eqs." is not. A separate concern: Making the conjunction particles ("and" and en-dash) parts of the hyperlinks is rather questionable. For instance, where exactly is the "and" in "Figs. 3 and 4" supposed to point to: to Figure 3, to Figure 4, or maybe (but hopefully not) to somewhere else? – Mico May 25 '17 at 16:34
  • @Mico, I just noted in the original .pdf of screenshot, "and" is just pointing to "Fig. 3" only one of them. I agreed with your reply. Thanks for that. – kamran May 25 '17 at 16:52

3 Answers3

6

I think it's a poor idea, typographically speaking, to make the conjunction particle -- "and", "to", "--" (en-dash), etc. -- a part of the hyperlink.

The following adaptations to the cleveref package may be what you're looking for. Observe that a range of cross-referenced items can be specified either via \Cref or via \Crefrange.

enter image description here

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}

\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref}
\Crefname{figure}{Fig.}{Figs.}
\newcommand\crefrangeconjunction{--}

\begin{document}
\begin{figure}[t!]
\caption{Missing figure 1.}\label{fig:1}
\caption{Missing figure 2.}\label{fig:2}
\caption{Missing figure 3.}\label{fig:3}
\caption{Missing figure 4.}\label{fig:4}
\caption{Missing figure 5.}\label{fig:5}
\end{figure}

\obeylines % just for this example
Single figure: \Cref{fig:2}
Two figures: \Cref{fig:1,fig:3}
Range of consecutive figures: \Cref{fig:1,fig:2,fig:3}, \Crefrange{fig:1}{fig:5}
\end{document}
Mico
  • 506,678
2

You can use the cleverefpackage for this, along with some options for both hyperref and cleveref. With minor changes to the referencing commands used, that is, replace \figref with \cref and \crefrange where appropriate.

\documentclass[10pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{todonotes}
\usepackage[colorlinks,linkcolor=blue]{hyperref}
\usepackage[nameinlink,capitalise]{cleveref}

\newcommand{\crefrangeconjunction}{--}

\begin{document}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 1.}
\label{fig:missing Figure1}
\end{figure}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 2.}
\label{fig:missing Figure2}
\end{figure}

\begin{figure}[t]
\missingfigure[figwidth=6cm]{- << Ciel, mon mari >> dit-elle !}
\caption{Missing figure 3.}
\label{fig:missing Figure3}
\end{figure}
The single figure should be like that \cref{fig:missing Figure1}. And two figures be like that \cref{fig:missing Figure1,fig:missing Figure2}, moreover the combination of three figures like the \crefrange{fig:missing Figure1}{fig:missing Figure3} as you can see in the attached journal's screenshot.

\end{document}

This gives the output:

Output

sodd
  • 5,771
1

You can just create a new command called multiref and supply it the first and last figures

\newcommand{\multiref}[2]{\autoref{#1}-\ref{#2}} % from - to

Usage:

\multiref{fig:startfiglabel}{fig:endfiglabel}

This gives Figure 2-5 if your figure locations are the second and fifth figures.

  • I like this but it should use doubled -- for from - to, see https://tex.stackexchange.com/a/3821/171999 – Nyps Jul 28 '23 at 20:52