25

LaTeX commands like this:

Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times\ 25 = 625$, $C^{G} = 50 \times\ 50 = 2500$, $C^{G}
= 250 \times\ 250 = 62500$, and $C^{G} = 500 \times\ 500 = 250000$...

When compiled generate the following:

Spacing in Math Mode

The spacing in math mode really irritates me. There's too much white space around the equal sign, and the multiplication sign has more right padding than left padding. Is there any way to reduce this spacing?

  • 9
    There's no need to terminate a command with in math mode, because spaces are ignored there and placed automatically. – egreg Jan 22 '12 at 20:04
  • 19
    to eliminate the white spaces around the equal sign, simply enclose it in curly brackets $a{=}b$ – prettygully Jan 22 '12 at 21:40
  • @egreg thanx for the tip. I was not aware of that. – puk Jan 22 '12 at 21:59
  • This comment from @prettygully (on Jan 22 '12 at 21:40) about curly brackets should be one of the answers. – Jim C Apr 23 '17 at 6:29
51

Spacing around operators and relations in math mode are governed by specific skip lengths: \thinmuskip (default is 3mu), \medmuskip (default is 4mu plus 2mu minus 4mu) and \thickmuskip (default is 5mu plus 5mu). All are given in math units.

Here is an illustration of how a modification (setting them to 0mu) to these lengths affect the output (I've removed the forced space after \times):

Spacing in math mode

\documentclass{article}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

\verb|Normal:| \par
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.

\bigskip

\begingroup
\verb|\thinmuskip=0mu:| \par
\setlength{\thinmuskip}{0mu}
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.
\endgroup

\bigskip

\begingroup
\verb|\medmuskip=0mu:| \par
\setlength{\medmuskip}{0mu}
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.
\endgroup

\bigskip

\begingroup
\verb|\thickmuskip=0mu:| \par
\setlength{\thickmuskip}{0mu}
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.
\endgroup

\end{document}

Grouping (\begingroup...\endgroup) localizes the effect of the length modification. \medmuskip is used around binary operators (like \times) and \thickmuskip is used around binary relations (like =). It's best to stick to the standard LaTeX spacing rather that insert your own.

A good source of reading material on this is Herbert Voss' mathmode document. In particular, section 11 Space (p 28 onward).


Inline math forms part of the regular text construction. That's why there is some stretch in \medmuskip and \thickmuskip, which allows spacing around math operators/operands to change depending on their location within the paragraph text. Removing this glue allows for a more consistent setting of inline expressions. See Keeping the distance between mathematical symbols consistent?

However, it can also have some problematic effects with regards to line breaking, as is shown below:

enter image description here

\documentclass{article}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

\verb|Normal:| \par
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.

\bigskip

\begingroup
\verb|Math glue removed:| \par
\setlength{\medmuskip}{1\medmuskip}
\setlength{\thickmuskip}{1\thickmuskip}
Here again, four different simulations are run on networks of size 
$C^{G} = 25 \times 25 = 625$, $C^{G} = 50 \times 50 = 2500$, 
$C^{G} = 250 \times 250 = 62500$, and $C^{G} = 500 \times 500 = 250000$. Next,
for each network, the weights of the idiothetic connections are collected and
plotted based on radial distance, finally, they are averaged out over all
neurons and shifted and set about the centre of the graph.
\endgroup

\end{document}
  • 3
    Great answer! Maybe you could also mention that 1 mu is 1/18 em of \fam2? – morbusg Jan 22 '12 at 19:49
  • +1 for the examples, full code, and the additional begingroup/endgroup – puk Jan 22 '12 at 22:08
  • Something I've wondered for a reeeeeally long time. Thanks so much. – isomorphismes May 21 '14 at 8:35
  • +1! And what is the function of \thinmuskip? I can't see the difference in the example. – Eric Feb 2 '17 at 8:48
  • @Eric: See section 23.6.1 Classification of mu glue in TeX by Topic. – Werner Feb 2 '17 at 16:27
17

Why do you add extra space after the \times command. It completely scr*ws up the spacing. It looks very bad. I suggest you write $a \times b$, not $a \times\ b$. It'll look much better that way. Note that it also partially answers your question because you get less spacing.

8

A simple solution to eliminate the white spaces around the equal sign (or similar operators such as + or -), is to enclose it in curly brackets {}.

For example, write

$a{=}b$
$z{=}b{-}\frac{1}{(c{+}d)}$

instead of

$a=b$
$z=b-\frac{1}{(c+d)}$.

Credits: Thanks to user @prettygully who mentioned this as a comment to question on Jan 22 '12 at 21:40.

  • 1
    Well, this changes the meaning. There is a reason why space is added around operators. – Johannes_B Apr 23 '17 at 6:51
  • Could you please explain the reason so that I can understand better? Thank you| – Jim C Apr 23 '17 at 10:06
  • The accepted answer gives some links. But that is probably all LaTeX/TeX related. A book on mathematical typography might better explain the reasons. – Johannes_B Apr 23 '17 at 10:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.