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 ?
1 Answer
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).
-
\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)?– userOct 11, 2012 at 14:11 -
2
-
3@DanielE.Shub Not really:
\unskip
wouldn't remove it (there's\unkern
).– egregOct 11, 2012 at 17:16 -
-
3@snoram It's not wrong, but a macro is preferable, so you don't have to chase across your document for
\kern
if you realize that you have to change to 1/4 of an em instead of 1/6.– egregOct 24, 2018 at 10:05
\,
is non breaking.\,
is a non breaking space.