23

I want to reference labels in the sentence, as above in the code: like this - \ref{X,Y,Z} to give "Fig. 1a,1b,1c" or "Fig. 1a-c" in text.

\documentclass{article}

\usepackage{subfig}
\usepackage{cite}
\usepackage{hyperref}

\begin{document}    
...in the three statistically favoured models (Fig.~\ref{fig:LocalPoly1_residual,   
fig:IDW2_residual, fig:RBF_residual}) discussed below and not as well in the case of 
GlobalPoly5 (Fig.~\ref{fig:GlobalPoly5_residual}).

\begin{figure}[h!]
  \centering
  \subfloat[GlobalPoly5]{\label{fig:GlobalPoly5_residual}\includegraphics[width=0.25\textwidth]{"Data Analysis Files/GlobalPoly5_residual"}}                
  \subfloat[LocalPoly1]{\label{fig:LocalPoly1_residual}\includegraphics[width=0.25\textwidth]{"Data Analysis Files/LocalPoly1_residual"}}
  \subfloat[IDW2]{\label{fig:IDW2_residual}\includegraphics[width=0.25\textwidth]{"Data Analysis Files/IDW2_residual"}}
  \subfloat[RBF]{\label{fig:RBF_residual}\includegraphics[width=0.25\textwidth]{"Data Analysis Files/RBF_residual"}}
  \caption{Residual plots of each of the interpolators.}
  \label{fig:residualplot}
\end{figure}

\end{document}

@Leo Liu : it gives a lower case "f" for "figs." - do you know how make it uppercase "F" for consistency with my labelling elsewhere?

  • This is not a good question. What do you want to "work"? Please explain what you want. – Seamus Jun 14 '11 at 11:43
  • Sorry, I thought the title was sufficiently self-explanatory but perhaps I should be clearer. I want to reference labels in the sentence, as above in the code: like this - \ref{X,Y,Z}. – ptrcao Jun 14 '11 at 11:47
  • I have to agree with @Seamus. The actual question should be stated in the body, not only in the title. "Reference multiple labels" can mean different things and the reader should not be forced to read the requested solution from the code! – Martin Scharrer Jun 14 '11 at 11:58
  • Acknowledged, fixed. Let me know if anything else needs to be edited for clarity. Thanks. – ptrcao Jun 14 '11 at 11:59
  • What exact output do you want? Something like "Fig. 1a,b,c"? – Martin Scharrer Jun 14 '11 at 11:59
21

Just use \cref or \Cref from cleveref package to reference multiple labels in one command.

For example, \cref{fig1,fig2,fig3} is valid. And use \Cref for capitals.

  • 5
    I don't think you can have the space after the comma. (At least that didn't work when I just tested.) – Torbjørn T. Jun 14 '11 at 12:04
  • @Torbjorn: Indeed. It seems that cleveref should be impoved. – Leo Liu Jun 14 '11 at 12:23
  • @Leo Liu : see my OP for a refinement request – ptrcao Jun 14 '11 at 12:24
  • 1
    @ptrcao: Use \Cref. And you'd better read the package manual first for details. – Leo Liu Jun 14 '11 at 12:27
  • 1
    @Leo @ptrcao: \Cref is intended for the beginning of a sentence. To capitalize all refs, add the capitalize (or capitalise) option to the package, i.e. \usepackage[capitalize]{cleveref}. See the manual, section 5. – Torbjørn T. Jun 14 '11 at 16:12
14

without package cleveref the command must be \ref{..},\ref{...}

  • This didn't work for me – geo909 Jun 25 '15 at 12:53
  • 2
    that is not a useful description of your problem ... – user2478 Jun 25 '15 at 14:19
  • You're right.. What I meant is the following: If I have two theorems, say 1 and 2 labelled \label{first} and \label{second}, writing \ref{first}\ref{second} as you suggested will produce "12" and not "1,2", as the op was asking in his question. – geo909 Jun 25 '15 at 14:37
  • 1
    Yes, it must be \ref{...},\ref{...} – user2478 Jun 25 '15 at 16:05
  • Worked for me, and I don't an extra package. So, good! – juanmirocks Apr 23 '17 at 8:47

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.