Graphics, Figures & TablesTable exceeds Width of 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 Width of Page

Post by NELLLY »

Hi,

when I use the following commands, the table exceeds the width of the page. While in the document how to use the package booktabs it does not exceeds the width of the page. What should I do?

Code: Select all

%\listfiles
\documentclass{article}
%\usepackage{listings} \lstloadlanguages{XML}
\usepackage{booktabs}

\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}

\begin{document}
  \begin{table*}
    \centering
    \ra{0.5}
    \begin{tabular}{@{}rrrrcrrrcrrr@{}}\toprule
      & \multicolumn{3}{c}{$w = 8$} &\phantom{abc} & \multicolumn{3}{c}{$w = 16$} &\phantom{abc} & \multicolumn{3}{c}{$w = 32$} \\ \cmidrule{2-4} \cmidrule{6-8} \cmidrule{10-12}
      & $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$ && $t=0$ & $t=1$ & $t=2$ \\ \midrule
      $dir=1$ \\
      $c$ & 0.0790 & 0.1692 & 0.2945 && 0.3670 & 0.7187 & 3.1815 && - 1.0032 & - 1.7104 & - 21.7969 \\
      $c$ & - 0.8651& 50.0476& 5.9384&& - 9.0714& 297.0923& 46.2143&& 4.3590& 34.5809& 76.9167 \\
      $c$ & 124.2756& - 50.9612& - 14.2721&& 128.2265& - 630.5455& - 381.0930&& - 121.0518& - 137.1210& - 220.2500 \\
      $dir=0$ \\
      $c$ & 0.0357& 1.2473& 0.2119&& 0.3593& - 0.2755& 2.1764&& - 1.2998& - 3.8202& - 1.2784 \\
      $c$ & - 17.9048& - 37.1111& 8.8591&& - 30.7381& - 9.5952& - 3.0000&& - 11.1631& - 5.7108& - 15.6728 \\
      $c$ & 105.5518& 232.1160& - 94.7351&& 100.2497& 141.2778& - 259.7326&& 52.5745& 10.1098& - 140.2130 \\ \bottomrule
    \end{tabular}
    \caption{Caption}
  \end{table*}
\end{document}

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Table exceeds Width of Page

Post by cgnieder »

Maybe you can combine two things: make the table font size smaller and let it stick into the margins a bit. In an example below I show a possibility how to do that. I also removed the superfluous empty columns and the repeated use of mathmode in the cells. Instead I put the whole first column in mathmode and used S columns (as provided by the siunitx package) for the remaining columns in order to align the numbers at their decimal point and get a minus sign instead of a dash for the negative values:

Code: Select all

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{siunitx}

\usepackage{lipsum}% dummy text
\begin{document}
\lipsum[1]

\begin{table}[ht]
  \makebox[\textwidth][c]{\footnotesize
  \begin{tabular}{@{}>{$}r<{$}@{}*{9}{S[table-format=-3.4]}@{}}
    \toprule
      & \multicolumn{3}{c}{$w = 8$}
      & \multicolumn{3}{c}{$w = 16$}
      & \multicolumn{3}{c}{$w = 32$} \\
    \cmidrule(lr){2-4} \cmidrule(lr){5-7} \cmidrule(lr){8-10}
      & {$t=0$} & {$t=1$} & {$t=2$}
      & {$t=0$} & {$t=1$} & {$t=2$}
      & {$t=0$} & {$t=1$} & {$t=2$} \\
    \midrule
      dir=1 \\
      c
      & 0.0790 & 0.1692 & 0.2945
      & 0.3670 & 0.7187 & 3.1815
      & - 1.0032 & - 1.7104 & - 21.7969 \\
      c
      & - 0.8651& 50.0476& 5.9384
      & - 9.0714& 297.0923& 46.2143
      & 4.3590& 34.5809& 76.9167 \\
      c
      & 124.2756& - 50.9612& - 14.2721
      & 128.2265& - 630.5455& - 381.0930
      & - 121.0518& - 137.1210& - 220.2500 \\
      dir=0 \\
      c
      & 0.0357& 1.2473& 0.2119
      & 0.3593& - 0.2755& 2.1764
      & - 1.2998& - 3.8202& - 1.2784 \\
      c
      & - 17.9048& - 37.1111& 8.8591
      & - 30.7381& - 9.5952& - 3.0000
      & - 11.1631& - 5.7108& - 15.6728 \\
      c
      & 105.5518& 232.1160& - 94.7351
      & 100.2497& 141.2778& - 259.7326
      & 52.5745& 10.1098& - 140.2130 \\
    \bottomrule
  \end{tabular}}
  \caption{Caption}
\end{table}

\lipsum[2]

\end{document}
table.png
table.png (52.33 KiB) Viewed 7226 times
Regards
site moderator & package author
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Table exceeds Width of Page

Post by NELLLY »

Hi
I saved the siunitx.sty file and when I tried the proposed solution I get the following error

Code: Select all

Package siunitx error:not running under e-tex
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Table exceeds Width of Page

Post by cgnieder »

Sounds like you have a very outdated TeX distribution. siunitx requires an up to date distribution so you should probably install MiKTeX 2.9 or TeX Live 2012.

Regards
site moderator & package author
User avatar
svend_tveskaeg
Posts: 478
Joined: Sun Jul 12, 2009 5:31 am

Table exceeds Width of Page

Post by svend_tveskaeg »

I can recommend TeX Live 2012; it is easy to keep up to date. (I don't know about MiKTeX.)
``In the game of chess, you can never let your adversary see your pieces.''
-- Zapp Brannigan, Futurama (season 1, episode 4)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table exceeds Width of Page

Post by localghost »

cgnieder wrote:Sounds like you have a very outdated TeX distribution. […]
Indeed it is. Hence an upgrade is strongly recommendable. Otherwise there will be much more trouble in the future.


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

Re: Table exceeds Width of Page

Post by NELLLY »

Hello
Thanks for your answers. Is there any other solution to avoid the use of siunitx package. I made a search on how to use TexLive2012 and it seems that it needs many steps. I didn't have enough time to install it.
Thanks.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Table exceeds Width of Page

Post by Stefan Kottwitz »

I guess you don't want to risk a working LaTeX environment on your computer for installing a new system. You could try a LaTeX online compiler, such as writeLaTeX, Spandex.io or ShareLaTeX, which use a current TeX version. They usually provide a free account plus advanced paid services, so you could simply try. Once you made sure you can compile online, you can safely remove your old TeX installation in favor of a new one.

Stefan
LaTeX.org admin
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Re: Table exceeds Width of Page

Post by NELLLY »

Exactly, I didn't want to take such risk and lose all the package that I have installed previously. I just tried the link you gave me Stefan and the solution of gnieder works very well. Many thanks.
Post Reply