In my LaTeX document I have quite a few large tables where I would like to set the first row in bold font as well as the first column. This works nicely with some well-known tricks. However, when my first column is in math mode, compilation fails with "command \bfseries invalid in math mode".
When I use an empty dummy first column before the math column everything works fine, except for some extra indentation before the first column - see the attached M(N)WE.
Any ideas how I could get a nicely aligned first column in math mode?
\documentclass{article}
\usepackage{array}
\usepackage{booktabs} % midrule, tabularnewline
\usepackage{amssymb} % boldmath
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}#1\ignorespaces}
\begin{document}
% works fine but gives unwanted indent:
\begin{tabular}{@{}+p{0pt} >{\boldmath$}l<{$} ^c *{2}{^c}@{}}\toprule
\rowstyle{\bfseries}
&n &2 &1 &0\tabularnewline
&x[n] &1 &0 &3 \tabularnewline \midrule
&2x[n] &5 &0 &1 \tabularnewline
&y[n]=\sum{}&&1 &0\tabularnewline \bottomrule
\end{tabular}
\vspace{1 cm}
% gives the error described above:
\begin{tabular}{@{}>{\boldmath$}l<{$} +c *{2}{^c}@{}}\toprule
\rowstyle{\bfseries}
n &2 &1 &0\tabularnewline
x[n] &1 &0 &3 \tabularnewline \midrule
2x[n] &5 &0 &1 \tabularnewline
y[n]=\sum{}&&1 &0\tabularnewline \bottomrule
\end{tabular}
\end{document}