[Tex/LaTex] table overflows the page

longtabletables

I use \documentclass[a4paper,14pt]{report} and the longtable package. Also I have

\usepackage[left=3cm,right=1cm,top=2cm,bottom=2cm,bindingoffset=0cm]{geometry}

in the preamble.

I have some problems with the table:

\begin{longtable}{|p{50mm}|p{50mm}|p{50mm}|}

(I've tried {|p{0.1\textwidth}|p{0.2\textwidth}|p{0.2\textwidth}|}) but it makes no sense).

I'm very new to LaTeX and all help will be appreciated! What's wrong?

Best Answer

Your line width is 17cm: A4 paper is 21cm wide and you want margins 3cm wide on the left and 1cm wide on the right. With the shown input

\begin{longtable}{|p{50mm}|p{50mm}|p{50mm}|}

you don't get an overfull box. Indeed the width of the table is

150mm + 6\tabcolsep + 4*0.4pt = 163.215mm

as \tabcolsep is usually 6pt and the vertical rules are 0.4pt wide. But your example is not what you show, since it' obvious that the second column is much wider than the first one (I suspect 100mm instead of 50). If the longtable preamble is

\begin{longtable}{|p{50mm}|p{100mm}|p{100mm}|}

it's clear that the table will not fit in the line width. If you need a table where the second and third columns are twice as wide as the first one, you can do

\begin{longtable}{|p{\dimexpr.2\textwidth-2\tabcolsep-0.8pt}|
                   p{\dimexpr.4\textwidth-2\tabcolsep-0.4pt}|
                   p{\dimexpr.4\textwidth-2\tabcolsep-0.4pt}|}

Actually the first column is not exactly half of the second (it's shortened by 0.4pt), but this shouln't be a problem. This table will occupy exactly the line width. Just remember that LaTeX adds \tabcolsep at both sides of each column.

You can play with this measures, as long as the sum of the factors to \textwidth is 1, or try with Herbert's trick if the first column's width must be computed automatically.

Wide and long tables often require manual intervention.

Related Question