I can use ~ to produce a non-breaking space. But it is too large for me, and I would like a non-breaking space of the size of \, for example. Is it possible ?
- 250,273
- 8,167
1 Answers
There are two kinds of spacing that TeX can use: skips and kerns. The first sort of space can be flexible (the interword space is a skip, for instance), while the second one is rigid.
Both disappear at line breaks, but TeX will never break a line at a kern (unless it's followed by a skip), while it's willing to do it at skips. Therefore
word\,word
would never be broken across lines.
The command \, inserts a kern, precisely it's defined (in text mode) as
\kern 0.16667em
(where 1em is approximately the width of an uppercase "M", whence the name, or near the font size in points); so the space inserted by \, is 1/6 of an em.
Conversely, ~ is defined as a skip: its definition is \nobreakspace, which translates into
\leavevmode\nobreak\
(the last is "backslash+space"). There will be no line break at it, because the skip inserted by \<space> is preceded by so high a penalty that breaks are impossible (\nobreak translates into \penalty 10000).
You can space by inserting \kern yourself, but using a macro is preferable. If you need that the space is non breakable and flexible, use the same trick as ~:
\nobreak\hspace{.16667em plus .08333em}
would insert a space normally equal to 1/6 of an em, but stretchable to 1/4 of an em.
I left out the \leavevmode because such spaces should always be inserted between words. LaTeX takes that precaution, because users might use ~ in order to indent lines (which is not the best thing to do, though).
- 1,121,712
-
\nobreak\hspace{.16667em plus .13333em}would insert a space normally equal to 1/6 of an em, but stretchable to 1/5 of an em. Are you sure that's right? Maybe I just am not familiar with the syntax, but it seems like that space would be stretchable to about 0.3em. If you want stretchable to approximately 1/5 em, shouldn't that be.16667em plus .03333em(which works out to .19997em)? – user Oct 11 '12 at 14:11 -
2
-
3
-
-
4@snoram It's not wrong, but a macro is preferable, so you don't have to chase across your document for
\kernif you realize that you have to change to 1/4 of an em instead of 1/6. – egreg Oct 24 '18 at 10:05
\,is non breaking. – egreg Oct 10 '12 at 11:55\,is a non breaking space. – egreg Oct 10 '12 at 13:24