Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
share|improve this question
    
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
add comment

2 Answers

up vote 2 down vote accepted

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).

share|improve this answer
add comment

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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