TransWikia.com

Aligning integers in a table with doubles and integers

TeX - LaTeX Asked by Tyler D on January 17, 2021

I have the following table:

documentclass[12pt, a4paper]{article}
usepackage[english]{babel}

usepackage{amsmath}
usepackage{amssymb} 
usepackage{amsthm}
usepackage{tabularx}
usepackage{array}
usepackage{pdflscape}
usepackage{longtable}
usepackage{rotating}
usepackage{afterpage}


usepackage{textcomp}
usepackage{tikz}
usetikzlibrary{arrows.meta, positioning}
usetikzlibrary{calc}
usepackage{booktabs, siunitx}
usepackage{dcolumn}
NewExpandableDocumentCommandmcc{O{1}m}
    {multicolumn{#1}{c}{#2}}




begin{document}



begin{table}[ht]
centering
scriptsize
setlengthtabcolsep{0pt}
caption{My caption}
begin{tabular*}{linewidth}{l @{extracolsep{fill}}*{5}{D{.}{.}{6}}}
toprule
& mcc[1]{1 (L)}
& mcc[1]{2}
& mcc[1]{3}
& mcc[1]{4}
& mcc[1]{5 (H)} \
midrule


multicolumn{5}{l}{textbf{This panel's title}}\
midrule
A (floats)   $beta$ &-0.49 &-0.17 &-0.01 & 0.16 & 0.47 \
B (floats)   &6.43 &6.91 &6.98 &6.92 &6.48 \
C (integers) &136 &241 &342 &441 &536 \

bottomrule
end{tabular*}
end{table}


end{document}

The table contains both doubles and integers and aligns floats by the .. However, I find that it looks a bit odd with the integers being left-aligned. Is it possible to have them right-aligned? Or aligning it somehow so it doesn’t look as weird as now.

enter image description here

One Answer

enter image description here

With use of the siunitx package:

documentclass[12pt, a4paper]{article}
usepackage{array}
usepackage{booktabs, siunitx}
NewExpandableDocumentCommandmcc{O{1}m}
    {multicolumn{#1}{c}{#2}}

begin{document}



begin{table}[ht]
    centering
    %scriptsize
    sisetup{table-format=-1.2,
             table-text-alignment=right}
    setlengthtabcolsep{0pt}
caption{My caption}
begin{tabular*}{linewidth}{l @{extracolsep{fill}}*{5}{S} }
toprule
    & mcc{1 (L)}   & mcc{2}  & mcc{3}    & mcc{4}   & mcc{5 (H)}   \
midrule
multicolumn{5}{l}{textbf{This panel's title}}\
midrule
A (floats)   $beta$ 
                & -0.49 & -0.17 & -0.01 & 0.16 &  0.47 \
B (floats)      &  6.43 &  6.91 &  6.98 &6.92  &  6.48 \
C (integers)    & {136} & {241} & {342} & {44} & {536} \
bottomrule
end{tabular*}
    end{table}
end{document}

Answered by Zarko on January 17, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP