Graphics, Figures & TablesTable exceeds page width

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
amegahed3
Posts: 15
Joined: Wed Feb 25, 2009 11:20 am

Table exceeds page width

Post by amegahed3 »

Hi All!

I'm a beginner in using latex, and I face the following problem:

I have a table that has its first row too wide (each cell in the first row, which contains the title of its entire column is too wide). The rest of the cells in the other rows are not too wide. So, what I wanna do is making those cells of the first row take 3 rows, so that the whole table width doesn't exceed the page width.

Here is the code that currently exceeds the page width. Compile it and you will understand what I mean:

Code: Select all

\begin{table}[h]
\centering

\begin{tabular}[c]{l|c|c|c|c|c|c|}
\hline
\multicolumn{1}{|l|}{Implementation \#} & 	Implementation Parameters	& Avg of M Problems & Stdev of Avg of M Problems & Expected Objective Fixing First Stage Variables & GAP & GAP Stdev\\
\hline
\multicolumn{1}{|l|}{1}	&  M=50, N=1000, N'=500	& 138090 & 11 & 138106 & 16 & 11\\
\hline
\multicolumn{1}{|l|}{2}	& M=50, N=100, N'=1000	& 138056 & 36 & 138213 & 157 & 36\\
\hline
\multicolumn{1}{|l|}{3} &	M=100, N=100, N'=1000 &	137961 & 20 & 138211 & 250 & 20\\
\hline
\multicolumn{1}{|l|}{4} &	M=50, N=500; N'=1000 &	138086 & 16	 & 138118 & 32 & 16\\
\hline
\end{tabular}
\end{table}
Any help will be greatly appreciated.

Thanks.

Aly

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table exceeds page width

Post by localghost »

Well, there's always room for optimization and lots of possibilities for changes. A first approach could look like the following example.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin1]{inputenc}
\usepackage{babel}
\usepackage[includeheadfoot,margin=2cm]{geometry}
\usepackage[font=small,labelfont=bf,tableposition=top]{caption}
\usepackage{booktabs,multirow}

\stelength{\parindent}{0em}

\begin{document}
  \begin{table}[!ht]
    \centering
    \footnotesize
    \caption{Caption to the Table}\label{tab:table}
    \begin{tabular}{lcccccc} \toprule
      Implementation & Implementation & Avg of M & Stdev of & Expected Objective & \multirow{3}{*}{GAP} & GAP \\
      \# & Parameters & Problems & Avg of M & Fixing First & & Stdev \\
      & & & Problems & Stage Variables & & \\ \midrule
      1 & M=50, N=1000, N'=500 & 138090 & 11 & 138106 & 16 & 11 \\
      2 & M=50, N=100, N'=1000 & 138056 & 36 & 138213 & 157 & 36 \\
      3 & M=100, N=100, N'=1000 & 137961 & 20 & 138211 & 250 & 20 \\
      4 & M=50, N=500; N'=1000 & 138086 & 16 & 138118 & 32 & 16 \\ \bottomrule
    \end{tabular}
  \end{table}
\end{document}
Other options could be to turn the table by using rotating or rotfloat. floatrow or hvfloat are other packages to handle floats. tabularx lets you create tables that fit the line width.


Best regards
Thorsten¹
amegahed3
Posts: 15
Joined: Wed Feb 25, 2009 11:20 am

Re: Table exceeds page width

Post by amegahed3 »

Thanks a lot, man, for you great help. It actually solved the problem completely.

But could you please give me a brief explanation of what was done in the code you sent, and so solved the problem, as I don't totally get it (I only found the problem solved when I used it :-) ).

Thanks.

Aly
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table exceeds page width

Post by localghost »

amegahed3 wrote:[...] But could you please give me a brief explanation of what was done in the code you sent [...]
Well, here we go. At first I decreased the font size of the table contents to that of footnotes. The table head has been spread over three lines to get narrower cells. One entry has been aligned by using the multirow package. The look of the table was generally tweaked by using the booktabs package. It is recommendable to abandon vertical lines for better legibility. The caption of the table has been customized with the caption package. Information about the used packages and their manuals can be found on CTAN.
Post Reply