1

Brief background: I am creating a table that contains some math mode as the column headers and numerics with and without brackets as data.

  1. I want to align all numbers in the table to their decimal and right-align the column headers to the numbers, too.
  2. At the same time, I want my table to stretch out across the entire page horizontally.

My problem: I can not figure out how to combine the alignment with stretching the table over the entire page horizontally. My current table achieves 2., but is not aligned at the decimal.

\documentclass[12pt]{report}

\usepackage{tabularx} %Used for autofitting column widths to textwidth
\usepackage{ragged2e} 
\usepackage{booktabs}
\newcolumntype{R}{>{\RaggedLeft}X}
\begin{document}

\begin{table}[h]
    \tiny
    \setlength\tabcolsep{0pt} % let LaTeX figure out amount of inter-column whitespace
    \begin{tabularx}{\textwidth}{m{0.0005\textwidth} R R R R R R R R R R R}
  \toprule
$i$ & $\beta^{1i}$ & $\beta^{2i}$ & $\beta^{3i}$ & $\beta^{4i}$ & $E(c^i)$ & $\sigma(\Delta c^i)$ & $E(r^{e,i})$ & $\sigma(r^i)$ & $trn^i$ & $Size^i$ & $BM^i$ \\ 
 & $(\cdot 100)$ & $(\cdot 100)$ & $(\cdot 100)$ & $(\cdot 100)$ & $(\%)$ & $(\%)$ & $(\%)$ & $(\%)$ & $(\%)$ & $(EUR)$ & \\
 \midrule
 1 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 \\
 & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49) \\
 \bottomrule
    \end{tabularx}
\end{table}

\end{document}

which results in

enter image description here

Can you please help in aligning the numbers at the decimal point while preserving the right-aligned column headers and keeping the table stretched over the entire page?

Thank you. C

2 Answers 2

1

With the help of siunitx to align the numbers and tabular* instead of tabularx to make sure the table is as wide as the textwidth:

enter image description here

\documentclass[12pt]{report}

\usepackage{booktabs}
\usepackage{siunitx}


\begin{document}

\begin{table}[h]
\sisetup{table-space-text-pre={(},
         table-space-text-post={)},
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=1.2, 
         table-text-alignment=right
        }
    \scriptsize
    \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}} *{11}{S}}
  \toprule
$i$ & {$\beta^{1i}$} & {$\beta^{2i}$} & {$\beta^{3i}$} & {$\beta^{4i}$} & {$E(c^i)$} & {$\sigma(\Delta c^i)$} & {$E(r^{e,i})$} & {$\sigma(r^i)$} & {$trn^i$} & {$Size^i$} & {$BM^i$} \\ 
 & {$(\cdot 100)$} & {$(\cdot 100)$} & {$(\cdot 100)$} & {$(\cdot 100)$} & {$(\%)$} & {$(\%)$} & {$(\%)$} & {$(\%)$} & {$(\%)$} & {$(EUR)$} & \\
 \midrule
 1 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 & 2.00 \\
 & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49)  & (1.49) \\
 \bottomrule
    \end{tabular*}
\end{table}

\end{document}
4
  • Thank you. I did not specify that sometimes, the values in the brackets have two digits before the decimal and some are negative. Currently, the leading bracket cuts into the leading digit for two-digit numbers. How can I solve this?
    – Chris937
    Feb 4, 2021 at 19:43
  • 1
    Adjust the table-format for these columns accordingly. (e.g. table-format=2.2, table-format=-1.2 or table-format=-2.2 instead of table-format=1.2)
    – leandriis
    Feb 4, 2021 at 19:55
  • Thank you. This way, the opening bracket always assumes that a negative two-digit number is following, it seems. Thus, we have a very long space after the opening bracket for one-digit positive numbers. Looks like this: ( 1.49). Is there a way for the opening bracket to match the individual number?
    – Chris937
    Feb 4, 2021 at 20:04
  • 1
    Add table-align-text-pre = false, to \sisetup.
    – leandriis
    Feb 4, 2021 at 20:06
1

With use of the tabularx package:

\documentclass[12pt]{report}
\usepackage{siunitx} 
\usepackage{ragged2e}
\usepackage{booktabs, tabularx}
\newcolumntype{R}{>{\RaggedLeft}X}
\newcommand\mcx[1]{\multicolumn{1}{>{\Centering}X}{#1}}

\begin{document}
    \begin{table}[ht]
    \footnotesize
\sisetup{table-space-text-pre={(},
         table-space-text-post={)},
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=1.2,
        }
\setlength\tabcolsep{3pt}
\begin{tabularx}{\textwidth}{@{} r *{11}{S} @{}}
  \toprule
$i$ & \mcx{$\beta^{1i}$}    & \mcx{$\beta^{2i}$}    & \mcx{$\beta^{3i}$}    
    & \mcx{$\beta^{4i}$}    & \mcx{$E(c^i)$}        & \mcx{$\sigma(\Delta c^i)$}
    & \mcx{$E(r^{e,i})$}    & \mcx{$\sigma(r^i)$}   & \mcx{$trn^i$} 
    & \mcx{$Size^i$}        & \mcx{$BM^i$}         \\
    & {$(\cdot 100)$} & {$(\cdot 100)$} & {$(\cdot 100)$} & {$(\cdot 100)$} 
    & {(\%)} & {(\%)} & {(\%)} & {(\%)} & {(\%)} & {(EUR)}   & \\
% table body
    \midrule
 1  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  & 2.00  \\
    & (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)& (1.49)\\
    \bottomrule
 \end{tabularx}
    \end{table}
\end{document}

enter image description here

You must log in to answer this question.

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