3
\documentclass{article}
\begin{document}
\begin{tabular}{r|r@{\,}l|}
1&2&300\\
10&-2&X\\
\multicolumn{2}{r@{\,}}{2}&\multicolumn{1}{l}{X}
\end{tabular}
\end{document}

According to Lamport, the columns formatting consists of three parts:

r| + r@{\,} + l|

hence I would expect the two X's to be in the same position. But the X in the third line is shifted to the right (compared to the X in the second line).

By trial and error I found a solution by replacing \multicolumn{1}{l}{X} with \multicolumn{1}{@{}l}{X}. What is the reason behind this behaviour?

David Carlisle
  • 757,742

1 Answers1

5

You only gave part of the rule, and the output you show is affected by the other part.

It is true that (apart from the first column) inter-column material from @{..} or | is added to the right hand edge of a column, so the @{\,} adds a thin space to the right edge of column 2, not the left edge of column 3.

But @ (unlike the ! added by the array package) does not only add the material specified in its argument; it removes the \tabcolsep space. \tabcolsep padding is added to both sides of each column and using @ removes it from the right side of the current column and the left edge of the following.

So column 3 has no \tabcolsep padding on the left and is flush against column 2, the simplest way to achieve that in a \multicolumn is as you show, to apply @{} which adds nothing but removes \tabcolsep space.

David Carlisle
  • 757,742
  • Thank you! If I interpret your answer correctly, the @{,} in \begin{tabular}{r|r@{,}l|} replaces the entire intercolumn space between columns 2 and 3, whereas @{,} in \multicolumn{2}{r@{,}}{2}&\multicolumn{1}{l}{X} replaces only the first half of the intercolumn space between columns 2 and 3; but not the second half (preceeding column 3). – László Battha Aug 10 '23 at 13:04
  • @LászlóBattha yes a multicolumn can not affect columns that it does not span.basically the final @{...} in a multicolumn argument acts like a final @{...] in a tabular argument and acts as if there is nothing to follow. – David Carlisle Aug 10 '23 at 15:32