I found Boris's suggestion to use siunitx to achieve number formatting in Hmisc::latex tables to almost be exactly what I was looking for: R, Sweave, Hmisc: pretty-print numbers

However, if you look closely at the table, the number columns line up poorly with the column labels. This is worse when using multicolumn labels (e.g., cgroup). In looking at the documentation (page 15, table 9) for siunitx, I think this is because it is centering the numbers at the decimal point.

Is it possible to use the number formatting functions of siunitx but justify the columns as \raggedleft (right aligned) within a call to Hmisc::latex?


1 Answer 1


You can check out the option table-format on page 51 of the documentation.

I can illustrate with this example based on the answer you linked to.


dat <-  matrix(c(1000, 100, 10000, 10000,3.145,1700.42), 2)
  booktabs=T,numeric.dollar=F,colheads=c("Col A","Col B","Col C"),
      colnamesTexCmd="bfseries", col.just=c("S[table-format = 4]",
                                            "S[table-format = 5]",
                                            "S[table-format = 4.3]"))


  • Perfect! Thank you for the reference and the example.
    – penguinv22
    Jul 31, 2012 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .