[Tex/LaTex] Bold row in table aligned with dcolumn

dcolumntables

I am generating a bunch of TeX-tables (with Stata), in which one particular row has to be highlighted (bold). I can however only modify the first column in there, hence I want to place a command in the first cell of column to make it bold(or not)

So far I've been using this "Make first row of table all bold", which does exactly what I want.

\documentclass[12pt]{standalone}
\usepackage{dcolumn}    
\newcolumntype{X}{>{\rowstyle{\relax}}l}
\newcolumntype{Y}{>{\currentrowstyle}c}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}}
\begin{document}
\begin{tabular}{XYY}
normal row & 1.1 & 2.2\\
bold row \rowstyle{\bfseries} & 1.1 & 2.2\\
\end{tabular}
\end{document}

Now, I decided to switch to dcolumn, which is great, but breaks the bold-workaround, as it wraps cells in mathmode. The solution David provided here (Decimals in table don't align with dcolumn when bolded) does not really work either, as it would require a \multicolumn{1}{B}{...} in every bold cell.

Simply using mathbf instead doesnt seem to do the trick. Any suggestions are greatly appreciated.

Best Answer

\documentclass[12pt]{standalone}
\usepackage{dcolumn}  

\makeatletter  
\newcolumntype{X}{>{\rowstyle{\relax}}l}
\newcolumntype{D}[3]{>{\currentrowstyle\DC@{#1}{#2}{#3}}c<{\DC@end}}
\makeatother
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}}
\begin{document}
\begin{tabular}{XD..{-1}D..{-1}}
normal row & 1.1 & 2.2\\
bold row \rowstyle{\bfseries\boldmath} & 1.1 & 2.2\\
\end{tabular}
\end{document}

enter image description here

Related Question