# Formatting *** in a regression result table

I have a code as given below:

\documentclass[10pt]{article}

\usepackage{ltablex}

\begin{document}
\begin{tabularx}{\textwidth}{@{}rr@{}}
A & $0.11^{***}$\\   & (-12.112) \\    B & $0.15^{*}$\\   & (-8.452)\\
C & $0.76^{}$\\   & (12.452)\\
\end{tabularx}

\end{document}


This produces a result as given below:

However, I want "stars (***/*) etc. to be formatted differently as given in the picture below:

Please let me know how to format the table. Thanks.

• In the example, all of the values with stars have the same number of d.p., so the stars naturally line up. That's not the case in your input: what should happen? – Joseph Wright May 31 '14 at 7:40
• yes, I want the stars to naturally line up, irrespective of the number of digits of the corresponding number. – Sumit May 31 '14 at 7:41

You may want to use the dcolumn package for this purpose: It provides a column type called D which serves to align numbers in a column on the decimal marker without need for further intervention to handle symbols such as (, ), and *.

Because the contents of a D column are automatically typeset in math mode, there's also no need to specify opening and closing  markers. However, if you have a cell -- say, in the header row -- in a D-type column that contains some text or other mostly non-numeric material, be sure to encase it in a \mulicolumn{1}{c}{<some text>} macro. In the MWE below, I've modified the numbers relative to your code to make them conform to the structure of the numbers in the screenshot you posted. \documentclass{article} \usepackage{dcolumn} \newcolumntype{d}[1]{D..{#1}} % for alignment of numbers on decimal marker \begin{document} \begin{tabular}{@{} r d{4.6} @{}} \hline % just to mark width of tabular env. A & 0.123^{***}\\ & (-12.11)\\ B & 0.456^{*} \\ & (-8.45)\\ C & 0.789^{**} \\ & (12.34)\\ \end{tabular} \end{document}  • I don't want to align on decimal markaers. Rather the close bracket ")" should be aligned to the last decimal number before *. – Sumit May 31 '14 at 8:03 • @Sumit In the example you give, all of the decimal markers are aligned. – Joseph Wright May 31 '14 at 8:04 • If you apply the d column type to the numbers shown in your screenshot -- where all numbers not in parentheses have exactly three decimal digits and those in parentheses have exactly two digits -- you'll get precisely the alignment you say you want. I'll post a revised MWE and screenshot to demonstrate the validity of this claim. – Mico May 31 '14 at 8:16 • @Mico thanks for your solution, it works. Can you let me know what does 4.6 represent? Thanks. – Sumit May 31 '14 at 8:30 • @Sumit - The 4 and 6 items in the argument of d{...} represent the maximal number of "digits" -- I put the words in quotes deliberately, see also below -- that may occur before and after the decimal marker in that column. (For other number configurations, you'd presumably need different digit counts.) Count each asterisk, minus sign, and parenthesis as a "digit". I chose 4 because of the "number" (-12.11) and 6 because of the "number" 0.123***. If you don't specify the digit counts, dcolumn will center the contents of the column, with less appealing results. – Mico May 31 '14 at 8:34 While it's a bit of a 'stretch' (as it wasn't part of the original design), the table code in siunitx should be able to sort this out. For example \documentclass{article} \usepackage{siunitx} \begin{document} \protected\def\stars#1{^{#1}} \begin{tabular}{@{}r S[ table-format = -2.3, input-close-uncertainty = , input-open-uncertainty = , table-space-text-pre = ( , % ) table-space-text-post = \stars{***}, table-align-text-post = false ]{}} A & 0.11\stars{***}\\ & (-12.112) \\ B & 0.15\stars{*} \\ & (-8.452) \\ C & 0.76 \\ & (12.452) \\ \end{tabular} \end{document}  where I've made addition of stars into a separate concept. If you want all of the stars in one column, remove table-align-text-post = false (which will align them after the space for numbers): \documentclass{article} \usepackage{siunitx} \begin{document} \protected\def\stars#1{^{#1}\$}
\begin{tabular}{@{}r
S[
table-format            = -2.3,
input-close-uncertainty = ,
input-open-uncertainty =  ,
table-space-text-pre   = ( , % )
table-space-text-post  = \stars{***},
]{}}
A & 0.11\stars{***}\\
& (-12.112)      \\
B & 0.15\stars{*}  \\
& (-8.452)       \\
C & 0.76           \\
& (12.452)       \\
\end{tabular}

\end{document}

• I'm not clear on exactly what needs to line up here: I've taken a guess. – Joseph Wright May 31 '14 at 7:52
• sorry, it doesn't work. Take a look at the example which I have provided. The stars are all aligned in a single line. – Sumit May 31 '14 at 8:02
• @Sumit Yes, that was what I asked about: I read 'naturally line up' as meaning they should abut the numbers. Will alter for the alternative. – Joseph Wright May 31 '14 at 8:03
• Thanks for the update. Now, the stars are all aligned, however there are spaces between 0.11 and stars. For instance, in the example I have provided there is no space between numbers and stars, and despite that the stars are all aligned. – Sumit May 31 '14 at 8:07
• @Sumit Yes, because they have three decimal places for the 'main' numbers but only two for the 'bracketed' ones: the stars and closing bracket therefore both 'trail' into the space at the end of the column. From your example input it's not clear what the form of all of your input is: should we assume that all of the starred numbers have one decimal place less than than the bracketed numbers? – Joseph Wright May 31 '14 at 8:17