I've seen examples referencing a table as follows:
Table~\ref{table:overview} shows an overview of all the elements.
What is the use of the tilde in front of \ref
or \cite
and when do you have to apply it?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityThe tilde ~
is an unbreakable space, i.e. the line will never be broken at this position. If you write Table~\ref{...}
the table number generated by \ref
will always be on the same line as Table
, which is the preferable formatting. Having "Table" at the end of a line and then "1" at the beginning of the next simply looks bad.
The tilde is also used in names if they include a title, like Dr.~Faust
, which will also ensure that the "Dr." and the name is not broken between two lines, and also ensures that the .
is not taken as a full-stop, which usually produces a larger space after it.
babel
e.g. with the ngerman
option, a sentence-final period won't be followed by an enlarged space.
Jan 16, 2012 at 17:22
From the TeX Book (Chapter 6: Running TeX, p 25):
[The
~
signs] are called ties, because they tie words together; i.e., TeX is supposed to treat~
as a normal space but not to break between lines there. A good typist will use ties within names, as shown in our example; further discussion of ties appears in Chapter 14.
Continued in Chapter 14: How TeX Breaks Paragraphs into Lines, p 91-93:
"Ties" - denoted by
~
in plain TeX - are the key to successful line breaking. Once you learn how to insert them, you will have graduated from the ranks of ordinary TeXnical typists to the select group of Distinguished TeXnicians. And it's really not difficult to train yourself to insert occasional ties, almost without thinking, as you type a manuscript.When you type
~
it's the same as typing a space, except that TeX won't break a line at this space. Furthermore, you shouldn't leave any blanks next to the~
, since they will count as additional spaces. If you put~
at the very end of a line in your input file, you'll get a wider space than you want, because the<return>
that follows the~
produces an extra space.We have already observed in Chapter 12 that it's generally a good idea to type
~
after an abbreviation that does not come at the end of a sentence. Ties also belong in several other places:
In references to named parts of a document:
Chapter~12
&Theorem~1.2
Appendix~A
&Table~\hbox{B-8}
Figure~3
&Lemmas 5 and~6
No
~
appears afterLemmas
in the final example, since there's no harm in having5~and~6
at the beginning of a line. The use of\hbox
is explained below.Between a person's forenames and between multiple surnames:
Donald~E. Knuth
&Luis~I. Trabb~Pardo
Bartel~Leendert van~der~Waerden
&Charles~XII
Note that it is sometimes better to hyphenate a name than to break it between words; e.g.,
Don-
andald~E.~Knuth
is more tolerable thanDonald
andE.~Knuth
. The previous rule can be regarded as a special case of this one, since we may think ofChapter~12
as a compound name; another example isregister~X
. Sometimes a name is so long that we dare not tie it all together, lest there be no way to break the line:
Charles Louis Xavier~Joseph de~la Vall\'ee~Poussin.
Between math symbols in apposition with nouns:
dimension~$d$
width~$w$
function~$f(x)$
string~$s$ of length~$l$
However, the last example should be compared with
string~$s$ of length $l$~or more.
Between symbols in series:
1,~2, or~3
$a$,~$b$, and~$c$.
1,~2, \dots,~$n$.
When a symbol is a tightly bound object of a preposition:
of~$x$
from 0 to~1
increase $z$ by~1
in common with~$m$.
The rule does not, however, apply to compound objects:
of $u$~and~$v$.
When mathematical phrases are rendered in words:
equals~$n$
&less than~$\epsilon$
&(given~$X$)
mod~2
&modulo~$p^e$
&for all large~$n$
Compare
is~15
withis 15~times the height
.When cases are being enumerated within a paragraph:
(b)~Show that $f(x)$ is (1)~continuous; (2)~bounded.
It would be nice to boil all of these rules down to one or two simple principles, and it would be even nicer if the rules could be automated so that keyboarding could be done without them; but subtle semantic considerations seem to be involved. Therefore it's best to use your own judgment with respect to ties. The computer needs your help.
A tie keeps TeX from breaking at a space, but sometimes you want to prevent the machine from breaking at a hyphen or a dash. This can be done by using
\hbox
, because TeX will not split up the contents of a box; boxes are indecomposable units, once they have been constructed. We have already illustrated this principle in theTable~\hbox{B-8}
example considered earlier. Another example occurs when you are typing the page numbers in a bibliographic reference: It doesn't look good to put22.
on a line by itself, so you can type\hbox{13--22}.
to prohibit breaking13--22.
On the other hand, TeX doesn't often choose line breaks at hyphens, so you needn't bother to insert\hbox
commands unless you need to correct a bad break that TeX has already made on a previous run.
Lemmas 5 and~6
as an example, but then include the explanation: No ~
appears after Lemmas
in the final example, since there's no harm in having 5~and~6
at the beginning of a line. I suspect a missing ~
after the first 5
?
the tilde is used to keep the table number (or other reference) from breaking to a new line during the justification process. it's especially nice to avoid this breaking when the cited reference is the last thing in a paragraph.
~
,\
,\@
), see section 2.6 of The Not So Short Introduction to LaTeX2e.