Header of table with math mode, align to decimal dot
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}
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}
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.