My question is in the title of this post, but extends to other referencing commands like \eqref, \citep, \citet (and the like) as well.
-
3I'd say this is somehow a duplicate of Good practice on spacing; it's a subcase of that question, even though this is not obvious from the question. – Hendrik Vogt Jan 25 '11 at 07:56
2 Answers
The ~ is a non-breaking space, (not really a symbol) so when you write in your text Table~\ref{mytable} it ensures that the Table part is kept together with the number. This is generally considered to be good for readability.
So that you don't forget, it's often helpful to make macros for references like these:
\newcommand*{\tabref}[1]{\tablename~\ref{#1}}
\newcommand*{\figref}[1]{\figurename~\ref{#1}}
Then you use \tabref{mytable} and \figref{myfig} in your text.
The refstyle package provides a generalised interface to automatically construct macros like those above.
The cleveref package with its \cref command is even more powerful, since it figures out what type of object your reference refers to and generates the correct text automatically (so you don't need different \ref commands for different reference types.)
If you are independently using the hyperref package, it also provides an \autoref command that works like cleveref's \cref command (and also makes the hyperlink target larger.)
-
5I recommend refstyle or cleveref for handling referencing macros. (As an extention to your macros.) Makes life much easier, I think. – Will Robertson Jan 24 '11 at 21:18
-
5Or you can use the
cleverefpackage and then only call\cref{mytable}instead ofTable~\ref{mytable}. – Jake Jan 24 '11 at 21:18 -
@Will (and Jake) Thanks for the suggestions about refstyle and cleveref; I've updated my answer. – Alan Munn Jan 24 '11 at 21:25
-
2
-
1While ~\cite() makes sense in numeric mode (where citations are "[2]") does it make sense with longer citations? I use it for both in case I ever switch, which seems like a bad thing. Thoughts? – TomOnTime Apr 22 '16 at 10:10
-
-
Are there any cases where it would be in appropriate for
\refto always have this behaviour? Why doesn't it come with this behaviour? – Marten Sep 21 '21 at 14:04 -
Also is there any way to redefine \ref so that it always does this? It does not seem easy since it has to affect what is coming before it. I would like syntax to stay the same so the
\tabrefetc solution would not work. – Marten Sep 21 '21 at 14:06 -
@Kvothe It wouldn't be wise to redefine
\refto do this; for a more automated and general approach I would probably usecleveref. – Alan Munn Sep 21 '21 at 16:08 -
@Alan, ok, but cleveref also can't do this right? I.e. replace \ref with some other command that uses the same syntax. It seems like it is a mistake in latex since it is generally accepted you should always write
~\ref. (Practically I will stick to never writing it then cycling through my text in the end with ctrl-f and fixing it up, which is okay enough, it is just a strange design flaw.). – Marten Sep 21 '21 at 17:21 -
@Kvothe No, that's not how
cleverefworks: it provides the name of the element being referred to by the counter automatically, and inserts the~for you. So instead of writingin Equation~\ref{myeq}you writein \cref{myeq}to produce the same output. So this is the modified\refcommand you want. – Alan Munn Sep 21 '21 at 17:42
The ~ is called a tie because it ties two words together like in Section~\ref{sec:intro}. The tie causes TeX never to break a line at a tie. Hence, Section and the reference will end up together on the same line, making them easy to read. Tying together what belongs together is good practice and is not limited to \ref. Another good use is tying an academic title to a name.
- 14,627
-
3
-
It is good for salutations like Dr. Mr. etc and also suffixes to name like sr. Jr. I II III etc. – Aku Jan 25 '11 at 17:48
-
1
-
@Herbert I think a
\after the dot is better (unless you're using\frenchspacing, but still...); the thin space is too small. Also I don't understand why Hyronymous (Hieronymus really) and Bosch should be tied.H*is the first name andBoschthe surname, which shouldn't be tied (Otherwise you might as well tieGeorgeandBushand I don't want any ties with them.) – Feb 28 '12 at 18:25 -
@Herbert: While many of Knuth's ideas were "good", not all are practiced in the typesetting world outside of the TeX universe. Here are a few of examples: While people never line-break between numbers and units, there is no obvious prohibition against linebreaks between first and middle name or middle name and last name (judging from general practice).
\frenchspacinghas been the norm in the US (and elsewhere even more so) outside of a typewriter context for many decades. Vertical line stretching is rarely done, if ever. But it certainly makes sense to use~for figures and tables. – Lover of Structure Jun 13 '12 at 19:17 -
@Herbert Just a thought: It does (imho) make sense though to avoid hyphenation of parts of personal names, because for each hyphen at the end of a line, the reader needs to ask himself whether the hyphen is part of the name or not (because there are names with hyphens where the part after the hyphen starts with a lowercase letter). – Lover of Structure Jun 14 '12 at 17:32