TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I thought I knew how to use a \hphantom{} but don't know of an easy way to handle this case due to the comma. I want to get the text aligned for the X row. I added the appropriate \hphantom{{}+1} after the comma on the X row and yet the spacing is not correct. If I add the \hphantom{{}+1} before the comma, as in the Z row the spacing is ok, but I want the comma on the left.

enter image description here

But surprisingly, if I add an additional phantom comma on the right hand side to all three rows, then things align properly:

enter image description here


  • What is the appropriate \hphantom to use to adjust for the spacing issues caused by the comma?
  • Why does adding an additional phantom comma to all three rows fix things?


  • Yes I could add an additional alignment point just before the that is text, but I want the entire text to be able to wrap properly if the text is longer than the width of the column.



    $X$~ &represents $n = 4k, \hphantom{{}+1}$ that is \ldots,\\
    $Y$~ &represents $n = 4k+1,              $ that is \ldots,\\
    $Z$~ &represents $n = 4k \hphantom{{}+1},$ that is \ldots,\\

But adding an additional phantom comma fixes the alignment:

    $X$~ &represents $n = 4k,   \hphantom{{}+1,}$ that is \ldots,\\
    $Y$~ &represents $n = 4k+1, \hphantom{,}$ that is \ldots,\\
    $Z$~ &represents $n = 4k    \hphantom{{}+1}, \hphantom{,}$ that is \ldots,\\
share|improve this question
Ok, hope this makes up for the hard question I posted earlier as this one seems that it should have an easy answer. – Peter Grill Feb 20 '13 at 3:49
The X comma sees the \hphantom as Ord and adds the spacing, the Z does not, compare $Z$~ &represents $n = 4k \hphantom{{}+1}, {}$ that is \ldots, with the X row. You can enclose the X comma in braces: {,}. For the second table: Every comma no has an following Ord to include its spacing. – Qrrbrbirlbel Feb 20 '13 at 3:52
@Qrrbrbirlbel: Not sure I understand fully. And how to explain that adding an additional phantom comma at the end of all three rows aligns things – Peter Grill Feb 20 '13 at 3:57
up vote 9 down vote accepted

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 ...


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.


\begin{tabularx}{\linewidth}{r@{ }X}
    $X$ & represents $n = 4k$,\hphantom{${}+1$} that is \ldots,\\
    $Y$ & represents $n = 4k+1$,                that is \ldots,

Notice also how to avoid the awkward $X$~ in the first column.

enter image description here

share|improve this answer
Totally agree with last line as being unacceptable, and also with punctuation needing to be outside of math mode - it never occurred to me to go back into math mode after the comma to fix the spacing issue. – Peter Grill Feb 20 '13 at 18:05
@PeterGrill This is however not a fix if the line wraps in the X column, because the space inside the \hphantom is frozen, while the one in 4k+1 is not. In this case you have to freeze also the formulas with ${n=4k}$ and ${n=4k+1}$ – egreg Feb 20 '13 at 18:40
If you are arguing that it is conceptually an error to consider punctuation part of the formula in inline math, why should one still consider it part of the formula in displayed math? Isn't it a formula in either case? (I also have the habit of including punctuation in my displayed formulas, but I'm just trying to follow your logic.) – justin Apr 19 at 1:09
@justin Punctuation doesn't belong to the formula, but in displays there is no choice but to put it along with the equation – egreg Apr 19 at 7:54

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


Ord Punct Ord


Ord none Punct thin Ord

Second row

1 ,

There is no symbol after the ,!


Ord Punct


Ord none Punct

This makes a deficit of one small space.

Third row

k \hphantom ,

There is no symbol after the ,!


Ord Ord Punct


Ord none Ord none Punct

Again, we are missing one small space compared to the first row.


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.


\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, \\


enter image description here

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 \hphantoms (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.


  1. American Mathematical Society, Mathematics into Type: Section 3 “Mathematics in Print”, pp. 37.

  2. mas in an answer to When one should use spacing line \quad or \,: Examples of category symbols

  3. 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)

    enter image description here

share|improve this answer
Most excellent explanation of the issue. – Peter Grill Feb 20 '13 at 18:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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