# underline a dcolumn cell

I have the following example code

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}

\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters}  {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols}  {nxbold}{OMS}{cmsy}{b}{n}

\begin{document}

\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter

\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{<<what to put here for underline cell?>>\DC@{#1}{#2}{#3}}c<{\DC@end}}

\makeatother

\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{6.2}}{12,345} & \multicolumn{1}{U{,}{,}{6.2}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}


The bold math type B is taken from the Z type from here and it works perfectly.

What do I have to put in the U type at <<what to put here for underline cell?>> to get an underlined cell?

I already tried \underline and \uline from the ulem package but both resulted in errors. Is this somehow possible with the dcolumn package?

• You like to underline just a number? or make line at bottom of cell? – Zarko Aug 5 '15 at 9:27
• Just the number. But I need the alignment along the commas to work too. – tiom Aug 5 '15 at 9:42

I suggest collcell package, which provides \collectcell and \endcollectcell command. You put these commands into U column definition.

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{collcell}
\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters}  {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols}  {nxbold}{OMS}{cmsy}{b}{n}

\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter

\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{\collectcell\underline\DC@{#1}{#2}{#3}}c<{\DC@end\endcollectcell}}

\makeatother
\begin{document}

\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{2.3}}{12,345} & \multicolumn{1}{U{,}{,}{2.3}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}
\end{document}


EDIT This version doesn't need collcell package

\documentclass[a4paper,12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{dcolumn}
\usepackage{tabularx}
\usepackage{multirow}

\DeclareMathVersion{nxbold}
\SetSymbolFont{operators}{nxbold}{OT1}{cmr} {b}{n}
\SetSymbolFont{letters}  {nxbold}{OML}{cmm} {b}{it}
\SetSymbolFont{symbols}  {nxbold}{OMS}{cmsy}{b}{n}

\newcolumntype{d}[1]{D{,}{,}{#1}}
\makeatletter

\newcolumntype{B}[3]{>{\mathversion{nxbold}\DC@{#1}{#2}{#3}}c<{\DC@end}}
\newcolumntype{U}[3]{>{$\@@underline\bgroup\hbox\bgroup\DC@{#1}{#2}{#3}}c<{\DC@end\egroup\egroup\m@th$}}

\makeatother
\begin{document}
\meaning\underline{Roba varia e eventuale}
\begin{table}[htbp]
\begin{center}
\begin{tabularx}{\textwidth}{d{2.3}d{2.3}}
\multicolumn{1}{c}{bold}& \multicolumn{1}{c}{underlined} \\
\multicolumn{1}{B{,}{,}{2.3}}{12,345} & \multicolumn{1}{U{,}{,}{2.3}}{56,789} \\
\end{tabularx}
\end{center}
\end{table}
\end{document}

• where to find collcell package? Is it par of some bundle? MikTeX doesn't find it (in on the fly installation)? – Zarko Aug 5 '15 at 9:48
• I found the package, problem is that temporary is MikTeX repository is down ... – Zarko Aug 5 '15 at 9:51
• I'm sorry, i don't know. I use TeXlive full installation. – skevin93 Aug 5 '15 at 9:52
• Works like a charm. Thanks for the solution. I'm using the one without the collcell package. – tiom Aug 5 '15 at 11:02

Here is another (incomplete) approach with siunitx which I am more used to. For the bold column, I managed to get it working. For the underlining, just single occurrences in one column seem to work. See my comments on where I got stuck.

% arara: pdflatex

\documentclass[12pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern} % if you do not want to stay with pixeled characters
\usepackage{siunitx}
\sisetup{output-decimal-marker = {,}} % or you set the localisation for your language e.g. 'locale = FR'
\usepackage[normalem]{ulem}
\usepackage{etoolbox}
\robustify\bfseries
\robustify\uline
\newcolumntype{B}[1]{>{\bfseries}S[table-format=#1, detect-weight]}
%\usepackage{collcell}
%\newcolumntype{U}[1]{>{\collectcell\uline}{S[table-format=#1]}<{\endcollectcell}} % does not work. It seems as if collcell can just handle standard column types.

\begin{document}
\begin{table}[h] % h just for demo. Do not use it...
\centering
\begin{tabular}{S[table-format=2.3, detect-weight]S[table-format=2.3]}
{bold} & {underlined} \\
\bfseries 12,345 & \uline{56,789} \\
\end{tabular}
\end{table}
\begin{table}[h]
\centering
\begin{tabular}{B{2.3}S[table-format=2.3]} % using \uline for all entries is a not solved problem still. See here http://tex.stackexchange.com/q/161032
{\normalfont bold} & {underlined} \\ % you can also use a \multicolumn{1}{c}{bold} here, as you did.
12,345 & \uline{56,789} \\
1.53 & 45.1 \\
13.4 & .456 \\
\end{tabular}
\end{table}
\end{document}


• Thanks for your solution but since I need more then one underlined number in a row I cant use it. – tiom Aug 5 '15 at 11:02