[Tex/LaTex] Latex Tables decimal point alignment for specific rows – dcolumn

dcolumntables

I am trying to put together a table that consists out of both text and numbers. Most of the numbers I want to align with respect to their decimal points. Nevertheless, some of the cells contain text and should therefore simply be centered. I managed to use the \multicolumn command to align specific cells correctly. Now I am wondering if there is a more efficient way to align whole rows (e.g. Row 1) instead of writing a \multicolumn command for every cell in that row. Below you can see how my table looks at the moment.

enter image description here

\documentclass{article}

% Column alignment
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}

\begin{tabular}{lcc}
Column 1 & Column 2 & Column 3 \\
Row 1 & \multicolumn{1}{d{3.2}}{555} & 555\\
Row 2 & \multicolumn{1}{d{3.2}}{7.77} & 7.77 \\
Row 3 & \multicolumn{1}{d{3.2}}{99.9} & 99.9 \\
Row 4 & Text 1 & Text 2
\end{tabular}

\end{document}

Best Answer

You can use siunitx, where cells that don't fit the numeric scheme have just to be braced and will be automatically centered.

\documentclass{article}

\usepackage{siunitx} % better

% the following two lines are not necessary for siunitx
\usepackage{dcolumn}
\newcolumntype{d}[1]{D{.}{.}{#1}}

\begin{document}

\section{With \texttt{dcolumn}}

\begin{tabular}{ld{3.2}c}
Column 1 & \multicolumn{1}{c}{Column 2} & Column 3 \\
Row 1 & 555 & 555\\
Row 2 & 7.77 & 7.77 \\
Row 3 & 99.9 & 99.9 \\
Row 4 & \multicolumn{1}{c}{Text 1} & Text 2
\end{tabular}

\section{With \texttt{siunitx}}

\begin{tabular}{lS[table-format=3.2]c}
Column 1 & {Column 2} & Column 3 \\
Row 1 & 555 & 555\\
Row 2 & 7.77 & 7.77 \\
Row 3 & 99.9 & 99.9 \\
Row 4 & {Text 1} & Text 2
\end{tabular}

\end{document}

enter image description here