# Bold row in table aligned with dcolumn

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.

• What do you mean with "outside of LaTeX"? Please show us some code of yours to play around with. Just one of the tables in a compilable environment. – LaRiFaRi Mar 21 '14 at 12:57
• You should take a look at the numprint package (§6 of the documentation: Printing aligned numbers in tabulars). It can manage bold numbers (in text and math modes) and non-numeric extra content of cells. – Bernard Mar 21 '14 at 13:17
• As David Carlisle explains in the answer you link to, \bfseries can't work because dcolumn uses math mode. – egreg Mar 21 '14 at 14:23
• This is why I wrote "which is great, but breaks the bold-workaround, as it wraps cells in mathmode" just after the link. I am searching for away to solve this. I am sorry if that was not clear – sheß Mar 21 '14 at 14:38

\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}


• This doesn't work, (at least not with the MWE above), as the \boldmath will end up being /within/ the math mode of the cell – sheß Mar 21 '14 at 15:06
• @sheß I added an image to my answer: the digits look bold to me. – David Carlisle Mar 21 '14 at 15:10
• I am sorry, i am not sure what i messed up. you are right of course – sheß Mar 21 '14 at 15:12
• Ah, now I see, is it actually using a D-column in your example? – sheß Mar 21 '14 at 17:39
• @sheß :-) Oh I didn't check I just assumed the example you provided was an example. I'll fix.... – David Carlisle Mar 21 '14 at 18:15

A solution with package siunitx:

\documentclass[12pt]{standalone}

\usepackage{array}
\usepackage{siunitx}

\newcolumntype{X}{%
>{\rowstyle{\relax}}l%
}
\newcolumntype{Y}{%
>{\currentrowstyle}S[detect-weight]%
}
\newcommand{\rowstyle}[1]{%
\protected\gdef\currentrowstyle{#1}%
}

\begin{document}
\begin{tabular}{XYY}
normal row & 1.1 & 2.2\\
normal row & 12.34 & 56.78\\
bold row \rowstyle{\bfseries} & 1.1 & 2.2\\
bold row \rowstyle{\bfseries} & 12.34 & 56.78\\
\end{tabular}
\end{document}


• great, i use this for now. i will just not (for now) mark it as accepted answer since it is technically not an answer to the question(-title). – sheß Mar 21 '14 at 15:08