Math Spacing in the presence of a trailing/non-trailing comma
First, let us agree that in all rows n = 4k + 1
and n = 4k \hphantom{{} + 1}
produces the same horizontal space.
LaTeX organizes every math symbol in categories (examples, see reference 2):
- Ordinary,
- Operator,
- Binary,
- Relation,
- Open,
- Close,
- Punctuation, and
- Inner.
These can be forced by \mathop
, \mathord
, \mathbin
and so on.
There are rules which horizontal space should be placed between two objects.
According to these rules a small space (\,
/\thinmuskip
) shall be placed between a symbol of category Punctuation and a symbol of category Ordinary and not between one of Ordinary and one of Punctuation (the order matters).
This rule makes the spacing in $1,2, 3$
to look like “1, 2, 3” and not “1,2,3” (spaces in math-mode have no effect). This is also the reason why using a comma to separate integer and decimal in numbers needs to be written as 123{,}456
. (The comma “doesn’t see” the 4
anymore and is at the end of a group: No spacing.)
Now, how does that look in your example? (I assume that the \hphantom
space is seen as an ordinary symbol (it has to be something).)
First Table
First row
…
k, \hphantom
Categories
… Ord Punct Ord
Spacing
… Ord none Punct thin Ord
Second row
…
1 ,
There is no symbol after the ,
!
Categoires
… Ord Punct
Spacing
… Ord none Punct
This makes a deficit of one small space.
Third row
k \hphantom ,
There is no symbol after the ,
!
Categoires
… Ord Ord Punct
Spacing
… Ord none Ord none Punct
Again, we are missing one small space compared to the first row.
Solution
I guess you want natural spacing after the comma when no math content follows (the space after math will be used anyway), so let’s make the comma in the first row unaware of its following content (solution to the question) or as egreg has stated, your comma is actually a text-comma, though I find the the , \hphantom{${}+1$} that
solution cumbersome, in this case it is semantically correct (solution to the problem).
Take a look at rows Y' and Z' where I added an ordinary atom {}
that effects the ,
as in your original X row the \hphantom
does.
Code
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{tabularx}{\linewidth}{>{$}r<{$}@{ }l}
X & represents $n = 4k, \hphantom{{}+1}$ that is \ldots, \\
X' & represents $n = 4k{,} \hphantom{{}+1}$ that is \ldots, \\
X'' & represents $n = 4k $,\hphantom{${}+1$} that is \ldots, \\
Y & represents $n = 4k+1, $ that is \ldots, \\
Y' & represents $n = 4k+1, {} $ that is \ldots, \\
Z & represents $n = 4k \hphantom{{}+1}, $ that is \ldots, \\
Z' & represents $n = 4k \hphantom{{}+1}, {}$ that is \ldots, \\
\end{tabularx}
\end{document}
Output
Second table
In the second table you added an phantom-ed ,
in every row, but every of these commas are not followed by any symbol. They introduce all the same spacing, but the new \hphantom
s (row Y and Z) act as ordinary symbols and activate thin spacing after the commas that were a last symbol in the first table’s row.
Reference
American Mathematical Society, Mathematics into Type: Section 3 “Mathematics in Print”, pp. 37.
mas in an answer to When one should use spacing line \quad or \,: Examples of category symbols
LaTeX Companion, second edition. (I only have the German edition: section 8.9 “Symbole in Formeln”, pp. 540ff. and Tabelle 8.7: Abstände zwischen Symbolen)
Apart from the fact that the third line is unacceptable, the error is in considering the comma part of the formula, which it isn't.
Text punctuation belongs in the formula only in displayed math, otherwise it should be typed outside the formula markers.
Consider reading
$X$ represents $4k$, that is ...
as
Mumble represents mumble, that is ...
In other words, change all math contents into a mumble. If the comma is inside, it would be included in the corresponding mumble, so it wouldn't have any effect on the reading (and the grammar).
In your example you want to have a space as wide as "+1", with proper spacing, because the formula is wider in one line than in the others. The comma is not under discussion, because it's present in all three instances.
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{r@{ }X}
$X$ & represents $n = 4k$,\hphantom{${}+1$} that is \ldots,\\
$Y$ & represents $n = 4k+1$, that is \ldots,
\end{tabularx}
\end{document}
Notice also how to avoid the awkward $X$~
in the first column.