3

I created this table using siunitx package since values must to be represented in scientific notation. Unfortunately the table goes out of margin. How can I fix the issue?

\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{siunitx}

\begin{document}

    \begin{table}[htp]
    \centering
    \rowcolors{1}{}{lightgray}
    \sisetup{table-format=1.4e06,exponent-product = \cdot}
    \begin{tabular}{lSSSSS}
        \toprule
        {\emph{Nodi}}      &        \multicolumn{5}{c}{Sistemi di trasmissione}        \\
        \cmidrule{2-6} &    {BC}    & {$\text{PNC}_{16}$} & {$\text{PNC}_{32}$} & {{$\text{PNC}_{64}$}} & {$\text{PNC}_{128}$} \\ \midrule
        1                  & 1.4307e-06 &  2.4116e-05  &  4.6601e-05  &   9.145e-05    &  1.9019e-04   \\
        3                  & 2,108e-06  &  2.5738e-05  &  5.1332e-05  &   9.775e-05    &  1.9374e-04   \\
        7                  & 2.7708e-06 &  2.7964e-05  &  5.324e-05   &   1.0158e-04   &  2.0066e-04   \\
        12                 & 3.2206e-06 &  2.905e-05   &  5.5356e-05  &   1.0441e-04   &  2.0528e-04   \\
        20                 & 3.6241e-06 &  2.9865e-05  &  5.6242e-05  &   1.0698e-04   &  2.0324e-04   \\
        25                 & 3.8909e-06 &  3.0289e-05  &  5.614e-05   &   1.0648e-04   &  2.0663e-04   \\
        35                 & 4.2468e-06 &  3.1154e-05  &  5.7399e-05  &   1.0791e-04   &  2.0598e-04   \\
        50                 & 4.4803e-06 &  3.1883e-05  &  5.8366e-05  &   1.0964e-04   &  2.0811e-04   \\
        65                 & 4.7681e-06 &  3.2091e-05  &  5.8808e-05  &   1.1044e-04   &  2.0992e-04   \\
        75                 & 4.9844e-06 &  3.2443e-05  &  5.9032e-05  &   1.099e-04    &  2.1003e-04   \\
        90                 & 5.1003e-06 &  3.2914e-05  &  5.9188e-05  &   1.1086e-04   &  2.0996e-04   \\
        100                & 5.2175e-06 &  3.3087e-05  &  5.9855e-05  &   1.1089e-04   &  2.1143e-04   \\ \bottomrule
    \end{tabular}
    \end{table}
\end{document}
  • put \small before the tabular? – David Carlisle Jan 10 '13 at 20:58
  • 1
    Please always post complete documents showing all packages used, it makes it much easier to process locally and see (in this cas)e how far into the margin it is. – David Carlisle Jan 10 '13 at 20:59
  • @DavidCarlisle I inserted \small. The table became smaller but is still out of margins – Mazzy Jan 10 '13 at 21:02
2

The table fits in the margins, without need of setting \small and of reducing too much \tabcolsep with the following code. Note the

table-format=1.4e-1

key, which states precisely the space you need. This means:

  • one digit for the integer part
  • four decimal digits
  • the sign for the exponent part
  • one digit for the exponent

Your table-format=1.4e06 reserved six digits for the exponent.

\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{siunitx,booktabs}
\usepackage[table]{xcolor}

\begin{document}

\begin{table}[htp]
\centering
\rowcolors{1}{}{lightgray}
\sisetup{table-format=1.4e-1,exponent-product = \cdot}
\addtolength{\tabcolsep}{-.5pt}
\begin{tabular}{rSSSSS}
\toprule
\multicolumn{1}{c}{\emph{Nodi}} &
 \multicolumn{5}{c}{Sistemi di trasmissione} \\
\cmidrule{2-6}
 & {BC} &
 {$\text{PNC}_{16}$} &
 {$\text{PNC}_{32}$} &
 {$\text{PNC}_{64}$} &
 {$\text{PNC}_{128}$} \\
\midrule
  1         & 1.4307e-06 &  2.4116e-05  &  4.6601e-05  &   9.145e-05    &  1.9019e-04   \\
  3         & 2,108e-06  &  2.5738e-05  &  5.1332e-05  &   9.775e-05    &  1.9374e-04   \\
  7         & 2.7708e-06 &  2.7964e-05  &  5.324e-05   &   1.0158e-04   &  2.0066e-04   \\
 12         & 3.2206e-06 &  2.905e-05   &  5.5356e-05  &   1.0441e-04   &  2.0528e-04   \\
 20         & 3.6241e-06 &  2.9865e-05  &  5.6242e-05  &   1.0698e-04   &  2.0324e-04   \\
 25         & 3.8909e-06 &  3.0289e-05  &  5.614e-05   &   1.0648e-04   &  2.0663e-04   \\
 35         & 4.2468e-06 &  3.1154e-05  &  5.7399e-05  &   1.0791e-04   &  2.0598e-04   \\
 50         & 4.4803e-06 &  3.1883e-05  &  5.8366e-05  &   1.0964e-04   &  2.0811e-04   \\
 65         & 4.7681e-06 &  3.2091e-05  &  5.8808e-05  &   1.1044e-04   &  2.0992e-04   \\
 75         & 4.9844e-06 &  3.2443e-05  &  5.9032e-05  &   1.099e-04    &  2.1003e-04   \\
 90         & 5.1003e-06 &  3.2914e-05  &  5.9188e-05  &   1.1086e-04   &  2.0996e-04   \\
100         & 5.2175e-06 &  3.3087e-05  &  5.9855e-05  &   1.1089e-04   &  2.1143e-04   \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

enter image description here

To be honest, the table width is 413.00468pt, while the \textwidth is 412.56499pt, so the difference is .44pt, less than the \hfuzz value of 0.5pt (0.18mm).

4

enter image description here

\documentclass{article}
\usepackage{siunitx}
\usepackage[table]{xcolor}
\usepackage{algpseudocode,booktabs}

\begin{document}

\begin{table}[htp]
  \centering
\small
\setlength\tabcolsep{0pt}
\rowcolors{1}{}{lightgray}
\sisetup{table-format=1.4e06,exponent-product = \cdot}
\begin{tabular}{@{\kern-1pt}lSSSSS@{\kern-1pt}}
    \toprule
    {\emph{Nodi}}      &        \multicolumn{5}{c}{Sistemi di trasmissione}        \\
    \cmidrule{2-6} &    {BC}    & {$\text{PNC}_{16}$} & {$\text{PNC}_{32}$} & {{$\text{PNC}_{64}$}} & {$\text{PNC}_{128}$} \\ \midrule
    1                  & 1.4307e-06 &  2.4116e-05  &  4.6601e-05  &   9.145e-05    &  1.9019e-04   \\
    3                  & 2,108e-06  &  2.5738e-05  &  5.1332e-05  &   9.775e-05    &  1.9374e-04   \\
    7                  & 2.7708e-06 &  2.7964e-05  &  5.324e-05   &   1.0158e-04   &  2.0066e-04   \\
    12                 & 3.2206e-06 &  2.905e-05   &  5.5356e-05  &   1.0441e-04   &  2.0528e-04   \\
    20                 & 3.6241e-06 &  2.9865e-05  &  5.6242e-05  &   1.0698e-04   &  2.0324e-04   \\
    25                 & 3.8909e-06 &  3.0289e-05  &  5.614e-05   &   1.0648e-04   &  2.0663e-04   \\
    35                 & 4.2468e-06 &  3.1154e-05  &  5.7399e-05  &   1.0791e-04   &  2.0598e-04   \\
    50                 & 4.4803e-06 &  3.1883e-05  &  5.8366e-05  &   1.0964e-04   &  2.0811e-04   \\
    65                 & 4.7681e-06 &  3.2091e-05  &  5.8808e-05  &   1.1044e-04   &  2.0992e-04   \\
    75                 & 4.9844e-06 &  3.2443e-05  &  5.9032e-05  &   1.099e-04    &  2.1003e-04   \\
    90                 & 5.1003e-06 &  3.2914e-05  &  5.9188e-05  &   1.1086e-04   &  2.0996e-04   \\
    100                & 5.2175e-06 &  3.3087e-05  &  5.9855e-05  &   1.1089e-04   &  2.1143e-04   \\ \bottomrule
\end{tabular}
\end{table}

\noindent X\dotfill X
\end{document}
0

After may years ... seems to be useful (my) answer on question how-to-make-a-column-specifier-which-combines-x-and-s, which was asked far later. Its adoption to this question is below.

Combination of tabularx table environment with combination of X (used for column headers in command \multicolumn{1}{... X}{...}) and S columns gives table width equal to text width and align of numbers as according to S column type:

enter image description here

(red lines show borders of page layout).

\documentclass[12pt,a4paper,oneside,openright]{book}
\usepackage[hmargin=3cm,vmargin=3cm,bindingoffset=0.5cm]{geometry}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{booktabs, multirow, tabularx}
\belowrulesep=0pt
\aboverulesep=0pt
\newcommand\mcx[1]{\multicolumn{1}{>{\centering\arraybackslash}X}{#1}}
\usepackage{siunitx}

\usepackage{showframe}% in real document had to be removed
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
    \begin{table}%[htp]
    \centering
    \renewcommand\arraystretch{1.1}
\rowcolors{1}{}{lightgray}
    \begin{tabularx}{\linewidth}{S[table-format=3.0]
                            *{5}{S[table-number-alignment = center,
                                   exponent-product       = \cdot,
                                   table-figures-integer  = 1,
                                   table-figures-decimal  = 4,
                                   table-figures-exponent = 1]}
                                }
    \toprule
{\multirow{2}{*}{\emph{Nodi}}}
    &   \multicolumn{5}{c}{Sistemi di trasmissione}        \\
    \cmidrule{2-6} 
    & \mcx{BC}   & \mcx{PNC$_{16}$} & \mcx{PNC$_{32}$}  & \mcx{PNC$_{64}$} & \mcx{PNC$_{128}$}  \\ \midrule
1   & 1.4307e-06 & 2.4116e-05       & 4.6601e-05        & 9.145e-05         & 1.9019e-04        \\
3   & 2,108e-06  & 2.5738e-05       & 5.1332e-05        & 9.775e-05         &  1.9374e-04       \\
7   & 2.7708e-06 & 2.7964e-05       & 5.324e-05         & 1.0158e-04        &  2.0066e-04       \\
12  & 3.2206e-06 & 2.905e-05        & 5.5356e-05        & 1.0441e-04        &  2.0528e-04       \\
20  & 3.6241e-06 & 2.9865e-05       & 5.6242e-05        & 1.0698e-04        &  2.0324e-04       \\
25  & 3.8909e-06 & 3.0289e-05       & 5.614e-05         & 1.0648e-04        &  2.0663e-04       \\
35  & 4.2468e-06 & 3.1154e-05       & 5.7399e-05        & 1.0791e-04        &  2.0598e-04       \\
50  & 4.4803e-06 & 3.1883e-05       & 5.8366e-05        & 1.0964e-04        &  2.0811e-04       \\
65  & 4.7681e-06 & 3.2091e-05       & 5.8808e-05        & 1.1044e-04        &  2.0992e-04       \\
75  & 4.9844e-06 & 3.2443e-05       & 5.9032e-05        & 1.099e-04         &  2.1003e-04       \\
90  & 5.1003e-06 & 3.2914e-05       & 5.9188e-05        & 1.1086e-04        &  2.0996e-04       \\
100 & 5.2175e-06 & 3.3087e-05       & 5.9855e-05        & 1.1089e-04        &  2.1143e-04       \\
    \bottomrule
    \end{tabularx}
    \end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.