# align numbers based on the decimal point with \textbf and stars in the table

I am stuck with the following problem.

I would like to align numbers based on the decimal.

The problem is that I have \mathbf statements as well as $^{***}$ or $^{**}$ or $^{*}$ in some of the columns.

Is there a way to align the numbers easily? I provide an example of the table below.

 \setlength\LTleft{0pt}            % default: \parindent

\setlength\LTright{0pt}           % default: \fill

\begin{center}

\begin{longtable}{@{\extracolsep{\fill}}*{1}{l}*{12}{c}}

\caption{\textbf{Table}}\\\hline

&\multicolumn{3}{c}{\emph{Panel A }}  & \multicolumn{3}{c}{\emph{Panel B }}\\

$Variable_{j,t} &$\mathbf{2.545}^{***}$& &$0.730$&$\mathbf{0.553}^{*}$& &$0.409$\\ &$(0.374)$& &$(1.777)$&$(0.326)$& &$(1.329)$\\$Variable3$& &$\mathbf{1.932}^{***}$&$1.218$& &$0.156$&$-0.249$\\ & &$(0.423)$&$(1.829)$& &$(0.349)$&$(1.315)$\\ & & & &$(0.126)$&$(0.122)$&$(0.123)$\\$pvalue$& 0.032 & 0.6811 & - & 0.016 &0.760 & - \\ \hline \end{longtable} \end{center}  • unrelated but never put longtable in a center environment Commented Jan 16, 2018 at 22:43 • you should make aur effort to help you by providing complete small document with your table, which we can copy and compile ... welcome to tex.se! Commented Jan 16, 2018 at 22:47 ## 2 Answers your code has more issue. find them with comparison with the following mwe. in it i use siunitx package for defining column types, booktabs for rules and etoolbox for robustness of command for boldface numbers: \documentclass{article} \usepackage{array, booktabs, longtable} \usepackage{siunitx} \usepackage{etoolbox}% <-- new \newcommand{\B}{\fontseries{b}\selectfont} % renew def. for non-extended bold font \robustify\B \begin{document} \setlength\LTleft{0pt} % default: \parindent \setlength\LTright{0pt} % default: \fill \begin{longtable}{@{} >{$}l<{$} *{6}{S[input-symbols = {(- )}, table-space-text-post={(}, table-space-text-post ={***}, detect-weight, table-format=1.3]} @{}} \caption{Table}\\ \toprule &\multicolumn{3}{c}{\emph{Panel A }} & \multicolumn{3}{c}{\emph{Panel B}} \\ \cmidrule(lr){2-4}\cmidrule(lr){5-7} \mathit{Variable}_{j,t} & \B 2.545$^{***}$& & 0.730 & \B 0.553$^*$& & 0.409 \\ & (0.374) & & (1.777) & 0.326 & & (1.329) \\ \mathit{Variable3} & & \B 1.932$^{***}\$  & 1.218 &   & 0.156 &  -0.249           \\
&                   & (0.423)           &  (1.829)  &   & (0.349)   & (1.315)       \\
&                   &   &               & (0.126)   & (0.122) & (0.123)             \\
\mathit{pvalue}         & 0.032 & 0.6811    &  {--}     &  0.016  &  0.760  &  {--}     \\
\bottomrule
\end{longtable}
\end{document}


This defines a version of dcolumns alignment using \boldmath instead of normal math, and defines bold math to use b (bold standard width characters) instead of bx (bold and wider characters) so that the digits line up;

\documentclass{article}

\usepackage{dcolumn}
\SetSymbolFont{operators}{bold}{OT1}{cmr} {b}{n}
\newcolumntype{d}{D..}
\makeatletter
\newcolumntype{b}[1]{>{\boldmath\DC@{.}{.}{#1}}c<{\DC@end}}
\makeatother
\begin{document}

\begin{tabular}{ld{3.4}}
aaa &1.2 \\
aa  & 012.3^{*{*}*} \\
aa  & 012.3 \\
x & \multicolumn{1}{b{3.2}}{12.34} \\
a &  654.78
\end{tabular}
\end{document}

\documentclass{article}

\usepackage{dcolumn}
\SetSymbolFont{operators}{bold}{OT1}{cmr} {b}{n}
\newcolumntype{d}{D..}
\makeatletter
\newcolumntype{b}[1]{>{\boldmath\DC@{.}{.}{#1}}c<{\DC@end}}
\makeatother
\begin{document}

\begin{tabular}{ld{3.4}}
aaa &1.2 \\
aa  & 012.3^{*{*}*} \\
aa  & 012.3 \\
x & \multicolumn{1}{b{3.4}}{12.34} \\
a &  654.78
\end{tabular}
\end{document}
`