# Header of table with math mode, align to decimal dot

I have to create a table with math symbols in the header and numbers in the body. I would like to align all the numbers to the decimal dot. To do that I used the siunitx package. The problem is that I am getting a "missing $inserted" error because of the header, although all the$ are at the right place. Can anyone help me?

Here is a MWE:

\documentclass{article}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}
\centering
\begin{tabular}{*7S[table-format=-3.2]}
\toprule
$\varphi$ & a & $\xi$ & $\alpha$ & $\beta$  & $\dot{W}^{M1}$ & $\dot{W}^{M2}$  \\
\midrule
0.00 &  45.00 & 22.48 & 0.02 &  0.17 &  250.00 &    250.00  \\
1.00 &  45.50 & 52.21 & 44.82 & 38.39 & 236.86 &    236.72  \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


Thank you

• add curles around every item in the topline where the columnformat is using S. Like: {a} – Runar Jun 21 '16 at 15:45

The reason you're getting a "missing $inserted" error message is that siunitx doesn't manage to parse the terms $\dot{W}^{M1}$ and $\dot{W}^{M2}$ correctly. As they're written, these terms satisfy LaTeX's own syntax rules for math formulas. See the following paragraph for a modification that helps out the siunitx parser. One solution is to enclose the terms in curly braces, effectively hiding them from siunitx's parser. A second solution is to enclose the two \dot{W} terms in curly braces, i.e., to write ${\dot{W}}^{M1}$ and ${\dot{W}}^{M2}$, respectively. With this method, there's no need to encase the full terms in curly braces -- siunitx parses them correctly and they will be centered automatically. Incidentally, the column specification *7S[table-format=-3.2] isn't really optimal, as (for instance) none of the numbers feature minus (or plus) symbols. If you want well-spaced (and well-centered) columns, it's worth specifying differing formats for column 1, columns 2-5, and columns 6 and 7, along the lines used in the code below. \documentclass{article} \usepackage{booktabs} \usepackage{siunitx} \begin{document} \begin{table} \centering \begin{tabular}{@{}S[table-format=1.2] *{4}{S[table-format=2.2]} *{2}{S[table-format=3.2]}@{}} \toprule$\varphi$& a &$\xi$&$\alpha$&$\beta$&${\dot{W}}^{M1}$&${\dot{W}}^{M2}$\\ \midrule 0.00 & 45.00 & 22.48 & 0.02 & 0.17 & 250.00 & 250.00 \\ 1.00 & 45.50 & 52.21 & 44.82 & 38.39 & 236.86 & 236.72 \\ \bottomrule \end{tabular} \end{table} \end{document}  • $\dot{W}^{M1}$ is perfectly good syntax and ${\dot{W}}^{M1}$ results in exactly the same output. – egreg Jun 21 '16 at 18:15 • @egreg - So is it the case that siunitx's parser isn't quite up to the job? – Mico Jun 21 '16 at 19:29 • Possibly so, but braces in the appropriate place solve the issue. But the main problem was the error about the syntax. – egreg Jun 21 '16 at 19:39 • @egreg - I've removed the claims that the OP's syntax was "barely legal". :-) – Mico Jun 21 '16 at 19:52 The S-columntype is from siunitx, which you of course already know. It tries to parse the numbers it finds in every cell. So when it finds some text, as in your toprow, it tries to parse that too. Solve this by placing curlybraces{} around each and one of the headertexts. Note that siunitx is semi-smart about this, so only those that could be mistaken for a number need to be protected. This can be seen in the siunitx-manual section 4.6 Tabular Material If the material could be mistaken for part of a number, it should be protected by braces. Code \documentclass{article} \usepackage{booktabs} \usepackage{siunitx} \begin{document} \begin{table} \centering \begin{tabular}{*7S[table-format=-3.2]} \toprule$\varphi$& {a} &$\xi$&$\alpha$&$\beta$&${\dot{W}^{M1}}$&${\dot{W}^{M2}}$\\ \\ \midrule 0.00 & 45.00 & 22.48 & 0.02 & 0.17 & 250.00 & 250.00 \\ 1.00 & 45.50 & 52.21 & 44.82 & 38.39 & 236.86 & 236.72 \\ \bottomrule \end{tabular} \end{table} \end{document}  • No, ${\dot{W}}^{M1}$ is not better syntax. It's worse, actually. – egreg Jun 21 '16 at 18:23 Headers of S columns should be enclosed in braces, unless they're \multicolumn. In some cases the siunitx package is able to recover with missing braces, but it's much easier adding them throughout. \documentclass{article} \usepackage{booktabs} \usepackage{siunitx} \begin{document} \begin{table} \centering \begin{tabular}{@{}S[table-format=1.2] *{4}{S[table-format=2.2]} *{2}{S[table-format=3.2]}@{}} \toprule {$\varphi$} & {a} & {$\xi$} & {$\alpha$} & {$\beta$} & {$\dot{W}^{M1}$} & {$\dot{W}^{M2}$} \\ \midrule 0.00 & 45.00 & 22.48 & 0.02 & 0.17 & 250.00 & 250.00 \\ 1.00 & 45.50 & 52.21 & 44.82 & 38.39 & 236.86 & 236.72 \\ \bottomrule \end{tabular} \end{table} \end{document}  In general, input such as $\dot{W}^{M1}$ is perfectly legal and produces no difference whatsoever with respect to ${\dot{W}}^{M1}\$, contrary to what other answers said. Here the problem is different and is best cured with outer braces.