Backslash Exclamation Mark in Tables – What Does \! Do?

tables

I just came across this ! (backslash exclamation mark) in the code for a table in somebody else's tex and I was wondering what it does.

\begin{table}[hbt]
        \centering
        \resizebox{\columnwidth}{!}{%
                \setlength\extrarowheight{1pt}
                \begin{tabular}{l | c c c | c r}
                        \toprule
                        \textbf{Thing} & $a$ & $b$ & $c$ & $d$ & $e$\\
                        \midrule
                        Stuff &  \!\!100\!\!  &  \!\!$10^{6}$\!\! & \!\!$\pi_0$\!\! & $\sigma$ & $2^{30}$\\
                        \bottomrule
                \end{tabular}%
        }
\end{table}

My tex editor says unrecognized command but it compiles just fine.
I've tried on overleaf and it seems to tighten the table somehow. Does anybody know more?

Best Answer

I don't know what the commands \! are supposed to do in the code you show, other than raising many errors.

The command \! is only allowed in math mode (unless redefined, which I'd discourage). It's purpose is to insert a negative thin space, which is useful in several places. For instance

\biggl(\frac{121}{12}-1\biggr)^{\!2}

is an improvement over ^{2}, because it moves the exponent towards the parenthesis and takes care of its bending.

Another place where it is helpful is in 2/\!\log x, because for technical reasons / is an ordinary symbol and TeX would add a thin space between it and the “log” operator.

Here's a picture: left the output with \!, right without.

enter image description here

The negative spacing of \! exactly matches the positive one by \, (which is automatically inserted in some places) in math mode. Note that \, can be used outside of math mode, where it inserts a sixth of a quad of space.

If you want to tighten a table, reduce the size of \tabcolsep. Using explicit negative spaces all over the place is not the correct way.

And never use \resizebox on a table.

Related Question