4

Brief background: I have created a table using the S column type provided by the siunitx package. This column type allows aligning the data and column headers just fine.

My problem: The table is too wide for my document, despite setting the width as \textwidth. I suspect this is because every column uses the same formatting and leaves room for a leading ( and a trailing ), even if it is not needed for each column.

MRE:

\documentclass[12pt,a4paper,titlepage,usenames]{article}

\usepackage[left=60mm,right=20mm,top=30mm,bottom=30mm]{geometry}
\usepackage{booktabs} 
\usepackage{siunitx}
\usepackage{tabu}

\begin{document}

\begin{table}[h]
\sisetup{
        table-space-text-pre={(},
         table-space-text-post={)},
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=2.2,
         table-text-alignment=right,
         table-align-text-pre = false,
         table-align-text-post = false
        }
    \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 & 1.43 & 0.00 & 0.00 & 0.00 & 0.26 & 0.00 & 0.96 & 1.97 & 0.50 & 28.45 & 3.14 \\ 
   & (21.34) & (7.49) & (-6.67) & (-3.39) &  &  &  &  &  &  &  \\ 
  3 & 1.41 & 0.00 & 0.00 & 0.00 & 0.25 & -0.00 & 0.66 & 1.78 & 0.83 & 61.16 & 0.88 \\ 
   & (29.14) & (9.91) & (-7.12) & (-1.27) &  &  &  &  &  &  &  \\ 
  5 & 1.30 & 0.00 & 0.00 & 0.00 & 0.25 & 0.00 & 1.56 & 2.11 & 14.69 & 5.45 & 0.00 \\ 
   & (20.18) & (9.84) & (-4.12) & (-3.29) &  &  &  &  &  &  &  \\ 
   \bottomrule

    \end{tabular*}
\end{table}


\end{document}

This leads to: enter image description here Where the two columns to the right overlap the tables edge.

My question: Can TEX figure out the correct column width automatically? How could I otherwise specify that for the columns on the right hand side, that not so much space for brackets is needed?

Thank you, C.

2 Answers 2

5

You can use individual table-format options for each S type column depending on its contents. S type columns without optional argument will use the table-format that is specified inside of the \sisetupcommand.

enter image description here

\documentclass[12pt,a4paper,titlepage]{article}

\usepackage[left=60mm,right=20mm,top=30mm,bottom=30mm]{geometry}
\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,
         table-align-text-pre = false,
         table-align-text-post = false
        }
    \scriptsize
    \setlength{\tabcolsep}{0pt}
    \begin{tabular*}{\textwidth}{l@{\extracolsep{\fill}} 
                                 S[table-format=2.2]
                                 S
                                 *{2}{S[table-format=-1.2]}
                                 *{4}{S}
                                 *{2}{S[table-format=2.2]}
                                 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 & 1.43 & 0.00 & 0.00 & 0.00 & 0.26 & 0.00 & 0.96 & 1.97 & 0.50 & 28.45 & 3.14 \\ 
   & (21.34) & (7.49) & (-6.67) & (-3.39) &  &  &  &  &  &  &  \\ 
  3 & 1.41 & 0.00 & 0.00 & 0.00 & 0.25 & -0.00 & 0.66 & 1.78 & 0.83 & 61.16 & 0.88 \\ 
   & (29.14) & (9.91) & (-7.12) & (-1.27) &  &  &  &  &  &  &  \\ 
  5 & 1.30 & 0.00 & 0.00 & 0.00 & 0.25 & 0.00 & 1.56 & 2.11 & 14.69 & 5.45 & 0.00 \\ 
   & (20.18) & (9.84) & (-4.12) & (-3.29) &  &  &  &  &  &  &  \\ 
   \bottomrule

    \end{tabular*}
\end{table}


\end{document}
4
  • 3
    +1. :-) I would suggest using text mode, though, or maybe \mathrm, for variable names such as trn, Size, BM, and especially EUR.
    – Mico
    Commented Feb 5, 2021 at 6:05
  • You're right. I'll change that. Admittedly, I did not look at the column headers too closely.
    – leandriis
    Commented Feb 5, 2021 at 6:55
  • Thank you for the suggestion. What would the benefit be of using text mode?
    – Chris937
    Commented Feb 5, 2021 at 10:07
  • 3
    @Chris937 - Take, for instance, "EUR": Unless I'm baldly mistaken, it's the three-letter code for a currency. By typesetting EUR in math mode, the string is interpreted as the product of variables named E, U, and R; that just can't be right, can it? (E.g., look at the gap between U and R.) Give changing {$(EUR)$} to {(EUR)} a try to see for yourself what a difference it makes.
    – Mico
    Commented Feb 5, 2021 at 10:24
3

I suggest to reduce \tabcolsep to 3.5pt and to apply @{\extracolsep{\fill}} from the first column:

\documentclass[12pt, a4paper, titlepage, usenames]{article}

\usepackage[left=60mm, right=20mm, vmargin=30mm, showframe]{geometry}
\usepackage{booktabs}
\usepackage{siunitx}

\begin{document}

\begin{table}[h]
\centering
\setlength{\tabcolsep}{3.5pt}
\sisetup{
        table-space-text-pre={(},
         table-space-text-post={)},
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=2.2,
         table-text-alignment=right,
         table-align-text-pre = false,
         table-align-text-post = false
        }
    \scriptsize
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}l*{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 & 1.43 & 0.00 & 0.00 & 0.00 & 0.26 & 0.00 & 0.96 & 1.97 & 0.50 & 28.45 & 3.14 \\
   & (21.34) & (7.49) & (-6.67) & (-3.39) & & & & & & & \\
  3 & 1.41 & 0.00 & 0.00 & 0.00 & 0.25 & -0.00 & 0.66 & 1.78 & 0.83 & 61.16 & 0.88 \\
   & (29.14) & (9.91) & (-7.12) & (-1.27) & & & & & & & \\
  5 & 1.30 & 0.00 & 0.00 & 0.00 & 0.25 & 0.00 & 1.56 & 2.11 & 14.69 & 5.45 & 0.00 \\
   & (20.18) & (9.84) & (-4.12) & (-3.29) & & & & & & & \\
   \bottomrule

    \end{tabular*}
\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 .