11

I need to reference several tables like Tables 1-3 or Tables 3.1 to 3.3 related with the section, I'm using the normal \ref{table1,table2,table3} to do what I want, but when I compile I get something like ??? Could someone tell me how to solve this little problem?

5
  • 1
    Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. You might also want to add to your question how you're including the pdfs etc.
    – Aradnix
    Sep 8, 2014 at 17:11
  • 1
    You should use the cleveref package for that: the \cref command compresses and sorts references automatically. It even saves you typing the word ‘tables’ whatever your language (well, a number of languages).
    – Bernard
    Sep 8, 2014 at 18:07
  • The ??? means the reference value is missing, which is sometimes solved by recompiling. Sep 8, 2014 at 18:39
  • 2
    If you don't want to use the package, you can write "see Tables \ref{table1}--\ref{table3}."
    – Tim A
    Sep 8, 2014 at 19:02
  • 1
    @Tim I would rather write "see Tables~\ref{table1}\nobreakdash--\ref{table3}". Better rendering :-) Jan 3, 2017 at 15:52

1 Answer 1

12

As already suggested in one of the comments, to achieve your objective you should load the cleveref package and type

\cref{table1,table2,table3}

Assuming these tables are numbered 1, 2, and 3, respectively, and assuming you're writing in English, you'll get

Tables 1--3

where "--" is supposed to represent an en-dash. (The conjuction particle is actually configurable; if one states \newcommand{\crefrangeconjunction}{ to~} in the preamble, one would get "Tables 1 to 3" instead of Tables 1--3.)

Note that you needn't actually enter the labels in consecutive order; if you'd written \cref{table2,table3,table1}, you'd still have gotten "Tables 1--3".

The package does impose an important restriction on the characters permitted in labels: since , is used as the separator between labels that form the the argument of \cref, you can't use , as a component of a label.

3
  • 2
    One can also use the \crefrange{table1}{table3} command to achieve a similar effect without having to type all of the objects between
    – darthbith
    Sep 8, 2014 at 20:05
  • 1
    @darthbith - The example I gave simply copied the setup given by the OP. For \crefrange{table1}{table3} to give the same result as \cref{table2,table3,table1}, one would also have to assume that there are no other tables in the range given by the lowest and higest table number. This may or may not be a valid assumption, right?
    – Mico
    Sep 8, 2014 at 20:14
  • Correct, \crefrange simply produces a consecutive range. Of course \cref and \crefrange do the same thing in this case, and in this case one can be more explicit (or save some typing for a very large range of objects) if it is wished :-)
    – darthbith
    Sep 8, 2014 at 20:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .