911

I know that \: in LaTeX produces a space when rendered.

Are there any alternatives, because my LaTeX renderer doesn't support \: (it renders it as text), and there is no help / FAQ that I can find.

doncherry
  • 54,637
Zerium
  • 12,559

1 Answers1

1375

There are a number of horizontal spacing macros for LaTeX:

  1. \, inserts a .16667em space in text mode, or \thinmuskip (equivalent to 3mu) in math mode; there's an equivalent \thinspace macro;
  2. \! is the negative equivalent to \,; there's an equivalent \negthinspace macro;
  3. \> (or \:) inserts a .2222em space in text mode, or \medmuskip (equivalent to 4.0mu plus 2.0mu minus 4.0mu) in math mode; there's an equivalent \medspace;
  4. \negmedspace is the negative equivalent to \medspace;
  5. \; inserts a .2777em space in text mode, or \thickmuskip (equivalent to 5.0mu plus 5.0mu) in math mode; there's an equivalent \thickspace;
  6. \negthickspace is the negative equivalent to \thickspace;
  7. \enspace inserts a space of .5em in text or math mode;
  8. \quad inserts a space of 1em in text or math mode;
  9. \qquad inserts a space of 2em in text or math mode;
  10. \kern <len> inserts a skip of <len> (may be negative) in text or math mode (a plain TeX skip); there's also a math-specific \mkern <math len>;
  11. \hskip <len> (similar to \kern);
  12. \hspace{<len>} inserts a space of length <len> (may be negative) in math or text mode (a LaTeX \hskip);
  13. \hphantom{<stuff>} inserts space of length equivalent to <stuff> in math or text mode. \phantom{<stuff>} is similar, inserting a horizontal and vertical space that matches <stuff>. Should be \protected when used in fragile commands (like \caption and sectional headings);
  14. \  inserts what is called a "control space" (in text or math mode);
  15. inserts an inter-word space in text mode (and is gobbled in math mode). Similarly for \space and { }.
  16. ~ inserts an "unbreakable" space (similar to an HTML &nbsp;) (in text or math mode);
  17. \hfill inserts a so-called "rubber length" or stretch between elements (in text or math mode). Note that you may need to provide a type of anchor to fill from/to; see What is the difference between \hspace*{\fill} and \hfill?;

Your usage should work in math mode, so try $\:$.

enter image description here

\documentclass{article}

\usepackage[margin=1in]{geometry}% Just for this example \setlength{\parindent}{0pt}% Just for this example

\begin{document}

There are a number of horizontal spacing macros for LaTeX:

\begin{tabular}{lp{5cm}} \verb|a,b| & a,b \quad $a, b$ \ \verb|a\thinspace b| & a\thinspace b \quad $a\thinspace b$ \ \verb|a!b| & a!b \quad $a!b$ \ \verb|a\negthinspace b| & a\negthinspace b \quad $a\negthinspace b$ \ \verb|a:b| & a:b \quad $a:b$ \ \verb|a&gt;b| & a&gt;b \quad $a&gt;b$ \ \verb|a\medspace b| & a\medspace b \quad $a\medspace b$ \ \verb|a\negmedspace b| & a\negmedspace b \quad $a\negmedspace b$ \ \verb|a;b| & a;b \quad $a;b$ \ \verb|a\thickspace b| & a\thickspace b \quad $a\thickspace b$ \ \verb|a\negthickspace b| & a\negthickspace b \quad $a\negthickspace b$ \ \verb|$a\mkern\thinmuskip b$| & $a\mkern\thinmuskip b$ (similar to \verb|,|) \ \verb|$a\mkern-\thinmuskip b$| & $a\mkern-\thinmuskip b$ (similar to \verb|!|) \ \verb|$a\mkern\medmuskip b$| & $a\mkern\medmuskip b$ (similar to \verb|:| or \verb|&gt;|) \ \verb|$a\mkern-\medmuskip b$| & $a\mkern-\medmuskip b$ (similar to \verb|\negmedspace|) \ \verb|$a\mkern\thickmuskip b$| & $a\mkern\thickmuskip b$ (similar to \verb|;|) \ \verb|$a\mkern-\thickmuskip b$| & $a\mkern-\thickmuskip b$ (similar to \verb|\negthickspace|) \ \verb|a\enspace b| & a\enspace b \ \verb|$a\enspace b$| & $a\enspace b$ \ \verb|a\quad b| & a\quad b \ \verb|$a\quad b$| & $a\quad b$ \ \verb|a\qquad b| & a\qquad b \ \verb|$a\qquad b$| & $a\qquad b$ \ \verb|a\hskip 1em b| & a\hskip 1em b \ \verb|$a\hskip 1em b$| & $a\hskip 1em b$ \ \verb|a\kern 1pc b| & a\kern 1pc b \ \verb|$a\kern 1pc b$| & $a\kern 1pc b$ \ \verb|$a\mkern 17mu b$| & $a\mkern 17mu b$ \ \verb|a\hspace{35pt}b| & a\hspace{35pt}b \ \verb|$a\hspace{35pt}b$| & $a\hspace{35pt}b$ \ \verb|axyzb| & axyzb \ \verb|a\hphantom{xyz}b| & a\hphantom{xyz}b (or just \verb|\phantom|) \ \verb|$axyzb$| & $axyzb$ \ \verb|$a\hphantom{xyz}b$| & $a\hphantom{xyz}b$ (or just \verb|\phantom|) \ \verb|a b| & a b \ \verb|$a b$| & $a b$ \ \verb|a\space b| & a\space b \ \verb|$a\space b$| & $a\space b$ \ \verb|a\ b| & a\ b \ \verb|$a\ b$| & $a\ b$ \ \verb|a{ }b| & a{ }b \ \verb|$a{ }b$| & $a{ }b$ \ \verb|a~b| & a~b \ \verb|$a~b$| & $a~b$ \ \verb|a\hfill b| & a\hfill b \ \verb|$a\hfill b$| & $a\hfill b$ \end{tabular}

\end{document}

Werner
  • 603,163
  • 19
    @Werner -- \ (backslash space) inserts a space equivalent to a word space; would be usefully added. also, in tabbing, \> will "add space" as a function of skipping to the next "tab stop"; adding this information may or may not be useful. – barbara beeton Jan 28 '14 at 15:14
  • 4
    How about italics correction, with \/? – Magnus Lie Hetland Mar 22 '14 at 12:04
  • 3
    Don't forget \kern and \mkern for text and math modes, respectively, when you wish to prevent the inadvertent addition of glue. – Steven B. Segletes May 08 '14 at 00:28
  • 2
    I just noticed that \hfil has already been suggested but it hasn't been included in your table. It's worthy to mention the construct a\hfill\hfill b\hfill c and the similar use of \hfil -- a\hfil\hfil b\hfil c – corporal May 08 '14 at 05:27
  • Also \space is missing from the list. – Alan Munn Nov 07 '16 at 23:09
  • @AlanMunn: Just added \space, ' ' and { }. – Werner Nov 07 '16 at 23:28
  • Note that most of the <len>'s are actually glue expressions. – Andrew Swann May 03 '17 at 06:51
  • @Werner I thought you might like to add \mspace as a LaTeX command with can deal the unit mu. See https://tex.stackexchange.com/questions/400680/unit-mu-unknown?noredirect=1#comment997528_400680 – user1 Nov 10 '17 at 16:19
  • In the description of \>, does "4.0mu plus 2.0mu minus 4.0mu" mean 2.0mu? If, so why not just say that? On the other hand, in the compiled output above, it looks like \> inserts exactly the same amount of space as \;, and I'm reading the description of \; as implying that it inserts 10.0mu. Is mu not a unit of length? (Hmm. Maybe relativistic effects. Some of those sequences must be moving more quickly than others.... :-) – Mars Mar 03 '18 at 16:50
  • 9
    @Mars: mu is a math unit, and varies in length depending on the style you're in (\displaystyle, \textstyle, \scriptstyle, or \scriptscriptstyle), similar to how em and ex varies within text mode based on the active font. Also, x plus y minus z refer to "rubber lengths" that can stretch from x to x+y or shrink to x-z, as needed, based on the surrounding text within the paragraph. If used within a box, or fully-stretchable environment (like a tabular's l, c or r columns), it'll result in a spacing of x, since there is no need to stretch or shrink. – Werner Mar 03 '18 at 20:45
  • Thanks Werner. That's helpful. I would suggest adding that kind of explanation to the answer, but having it in this comment is good enough. – Mars Mar 03 '18 at 21:07
  • Very simplistic but effective answer! – Jinhua Wang Apr 22 '19 at 18:48
  • why only fixed, how to custom cm etc – droid192 Apr 28 '19 at 19:35
  • 1
    @ItsmeJulian: You'll have to clarify what you mean by "custom cm, etc.". – Werner Apr 29 '19 at 17:47
  • 1
    @Werner Do you have a similar answer for the vertical spaces? Pleas add similar answer for the vertical spaces as well. – Qaher Oct 10 '19 at 10:33
  • Also, \llap and \rlap have a "no-space" effect (a bit OT maybe? :) – Matteo Gamboz May 08 '20 at 13:59
  • \, is non-breaking space too. – Velda May 13 '20 at 13:41
  • @Werner You can update a little bit your super response including the changes of the LaTeX October 2020? – Pablo González L Nov 02 '20 at 12:30
  • @Werner Thanks! – Pablo González L Nov 04 '20 at 01:01
  • 1
    Thanks for this great answer. It might help others to know that compilation with pdflatex (v3.14159265) and lualatex (v1.12.0), both from TeX Live 2020/Debian, seem to require a few changes:
    1. load the package amsmath (defines \!, \:, \>, \medspace, \negmedspace, \;, \thickspace, and \negthickspace);
    2. change the line \verb|a\>b| & a\>b \quad $a\>b$ \\ to \verb|$a\>b$| & $a\>b$ \\ (\> seems to be defined in math-mode only).
    – mgk Mar 15 '21 at 12:49
  • 1
    +1: I now realize that half of your reputation comes from this answer alone :). – Dr. Manuel Kuehner May 25 '21 at 01:14
  • that is the definite answer. I like it! – netskink Feb 14 '22 at 20:17
  • Will these work in \begin{gathered} ..... – user3582228 May 27 '22 at 19:11
  • @user3582228: Some work in math mode, some don't. – Werner May 31 '22 at 15:44
  • perhaps this answer should mention that \kern produces vertical space when in vertical mode (https://tex.stackexchange.com/a/41488/90645), so it's not exactly a horizontal spacing command (if I understand it correctly) – Daniel Diniz Oct 23 '22 at 15:24