Graphics, Figures & TablesTable exceeds the Width of the Page

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Table exceeds the Width of the Page

Post by NELLLY »

Hello,

I have to insert a wide table. I used the following commands but the last column exceeds the width of the page. What can I do?

Thanks

Code: Select all

\documentclass[12pt]{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx,amsmath}
\usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{array,booktabs,multirow}
\usepackage{mathtools}
\usepackage[format=hang]{caption}

\pagestyle{empty} \captionsetup{width=17cm}
\renewcommand{\baselinestretch}{1.5}\setlength{\evensidemargin}{3.5cm} \setlength{\textwidth}{6in}
\setlength{\textheight}{8.9in} \setlength{\evensidemargin}{3.5cm}
\setlength{\textwidth}{6in} \setlength{\topmargin}{-0.6in}
\setlength{\topmargin}{-0.2in} \setlength{\headsep}{.4in}
\setlength{\footnotesep}{.2in} \setlength{\parindent}{0.5cm}
\captionsetup{belowskip=12pt,aboveskip=4pt}

\begin{document}

\begin{table}
  \caption{}
    \makebox[\textwidth][c]{%
      \footnotesize%
      \begin{tabular}{
        c
        S[table-format=2.0]
        S[table-format=3.0]
        S[table-format=1.0]
        S[table-format=1.0]
        S[table-format=1.2]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format=2.2]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format= 1.5]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format=2.2]
        S[table-format=2.2]
      }\toprule [1.2pt]

\multirow{2}{*}[-0.75ex]{Run}& \multicolumn{8}{c}{ODP} &
\multicolumn{6}{c}{SP} & {$\Delta C_{{VSS|F_p}}$}  \\
\cmidrule(lr){2-9}\cmidrule(lr){10-15}


&{$n^*_1$}&{$n^*_2$}&{$UWL^*_1$}&{$UCL^*_1$}&{$UWL^*_2$}&{$UCL^*_2$}&{$h^*$}&{$ETCU^*$}&{ANSSC}&{ANOC}&{ANFA}&{ANSS}&{ANOS}&{ATS}&{(\%)}\\\midrule[1.2pt]

5&	72&	103&	4	&6	&5,90&	7,68&	3,27&	10,20&	0,30&	22,59&	0,00191&	0,50&	39,6&	2,56&	0,78\\
7&	2&	14&	0	&1	&0,26&	2,91&	1,76&	2,64&	0,57&	1,72&	0,00083&	0,64&	4,14&	6,75&	16,46\\
\bottomrule[1.2pt]
\end{tabular}
}
\end{table}

\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Table exceeds the Width of the Page

Post by Johannes_B »

Hi,

when a table is too wide it sticks into a margin. Your table is very wide, so my first suggestion would have been to rotate it using pdflscape. But since your textblock (made visible by showframe) is, well, let's be honest, a bit strange it won't fit, too.

Even lowering the spacing between the columns would be of any help. So my suggestion is to split the table somehow.
Maybe another forum member with more expertise has a better idea.

Code: Select all

\documentclass[12pt]{article}


\usepackage{booktabs}
 \usepackage{array}
 \usepackage{siunitx,amsmath}
 \usepackage[T1]{fontenc}
\usepackage{caption}
\usepackage{array,booktabs,multirow}
\usepackage{mathtools}
\usepackage{pdflscape}


\usepackage[format=hang]{caption}
\pagestyle{empty} \captionsetup{width=17cm}
\renewcommand{\baselinestretch}{1.5}\setlength{\evensidemargin}{3.5cm} \setlength{\textwidth}{6in}
\setlength{\textheight}{8.9in} \setlength{\evensidemargin}{3.5cm}
\setlength{\textwidth}{6in} \setlength{\topmargin}{-0.6in}
\setlength{\topmargin}{-0.2in} \setlength{\headsep}{.4in}
\setlength{\footnotesep}{.2in} \setlength{\parindent}{0.5cm}
\captionsetup{belowskip=12pt,aboveskip=4pt}
\usepackage{showframe}
    \begin{document}

\begin{landscape}
\begin{table}
\caption{}
\centering
\footnotesize
      \begin{tabular}{
        c
        S[table-format=2.0]
        S[table-format=3.0]
        S[table-format=1.0]
        S[table-format=1.0]
        S[table-format=1.2]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format=2.2]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format= 1.5]
        S[table-format=1.2]
        S[table-format=2.2]
        S[table-format=2.2]
        S[table-format=2.2]
      }\toprule [1.2pt]
\multirow{2}{*}[-0.75ex]{Run}& \multicolumn{8}{c}{ODP} &
\multicolumn{6}{c}{SP} & {$\Delta C_{{VSS|F_p}}$}  \\
\cmidrule(lr){2-9}\cmidrule(lr){10-15}
&{$n^*_1$}&{$n^*_2$}&{$UWL^*_1$}&{$UCL^*_1$}&{$UWL^*_2$}&{$UCL^*_2$}&{$h^*$}&{$ETCU^*$}&{ANSSC}&{ANOC}&{ANFA}&{ANSS}&{ANOS}&{ATS}&{(\%)}\\\midrule[1.2pt]
5&      72&     103&    4       &6      &5,90&  7,68&   3,27&   10,20&  0,30&   22,59&  0,00191&        0,50&   39,6&   2,56&   0,78\\
7&      2&      14&     0       &1      &0,26&  2,91&   1,76&   2,64&   0,57&   1,72&   0,00083&        0,64&   4,14&   6,75&   16,46\\
 \bottomrule[1.2pt]
      \end{tabular}
      \end{table}
  \end{landscape}
\end{document}
Best regards
Johannes
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table exceeds the Width of the Page

Post by localghost »

You could also try the sidewaystable environment from rotating. Note that this specific environment will automatically occupy a complete page.

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{geometry}
\geometry{
  text={6in,8.9in},
  headsep=.4in,
  footnotesep=.2in
}
\usepackage{caption}
\captionsetup{
  format=hang,
  width=17cm,
  aboveskip=4pt,
  belowskip=12pt
}
\usepackage{siunitx}
\usepackage{array,booktabs,multirow}
\usepackage{mathtools}  % loads »amsmath«
\usepackage{rotating}

\setlength{\parindent}{0.5cm}

\begin{document}
  \begin{sidewaystable}
    \caption{Dummy table}
    \label{tab:dummy}
    \footnotesize
    \begin{tabular}{
      c
      S[table-format=2.0]
      S[table-format=3.0]
      S[table-format=1.0]
      S[table-format=1.0]
      S[table-format=1.2]
      S[table-format=1.2]
      S[table-format=2.2]
      S[table-format=2.2]
      S[table-format=1.2]
      S[table-format=2.2]
      S[table-format=1.5]
      S[table-format=1.2]
      S[table-format=2.2]
      S[table-format=2.2]
      S[table-format=2.2]
    }\toprule [1.2pt]
      \multirow{2}{*}[-0.75ex]{Run}& \multicolumn{8}{c}{ODP} &
      \multicolumn{6}{c}{SP} & {$\Delta C_{{VSS|F_p}}$} \\
      \cmidrule(lr){2-9}\cmidrule(lr){10-15}
      & {$n^*_1$} & {$n^*_2$} & {$UWL^*_1$} & {$UCL^*_1$} & {$UWL^*_2$} & {$UCL^*_2$} & {$h^*$} & {$ETCU^*$} & {ANSSC} & {ANOC} & {ANFA} & {ANSS} & {ANOS} & {ATS} & {(\%)} \\ \midrule[1.2pt]
      5 & 72 & 103 & 4 & 6 & 5,90 & 7,68 & 3,27 & 10,20 & 0,30 & 22,59 & 0,00191 & 0,50 & 39,6 & 2,56 & 0,78 \\
      7 & 2 & 14 & 0  & 1 & 0,26 & 2,91 & 1,76 & 2,64 & 0,57 & 1,72 & 0,00083 & 0,64 & 4,14 & 6,75 & 16,46 \\ \bottomrule[1.2pt]
    \end{tabular}
  \end{sidewaystable}
\end{document}
Remarks:
  • You are loading packages twice.
  • You are doing settings twice.
  • Use geometry to set up page and paper dimensions (see code above).
  • Use setspace to get 1.5 line spacing.

Urgent recommendations:
  • Clean up your code for more clarity.
  • Read what people write to you. Some advices are not given to you for the first time.
  • Learn to use the Forum Search.
  • Read l2tabu!

Thorsten
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Re: Table exceeds the Width of the Page

Post by NELLLY »

Many thanks for your answers.
Post Reply