Graphics, Figures & TablesTable width longer than linewidth

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
JavierIEH
Posts: 2
Joined: Tue Nov 23, 2010 6:41 am

Table width longer than linewidth

Post by JavierIEH »

Hello. So I am trying to make a table with the width as long as the whole linewidth.
This table has 3 rows and the sum of their widths is 1.0\linewidth as you can see on my code:

Code: Select all

\begin{longtable}[hbt]{|p{0.15\linewidth}|p{0.35\linewidth}|p{0.5\linewidth}|}
0.15 + 0.35 + 0.5 = 1. So, the whole table width should take up all of the linewidth space right? But here is what happens.
widelongtable.png
widelongtable.png (39.07 KiB) Viewed 5576 times
You can see that in the previous page, the text has 1.5cm of right margin (defined with geometry package)

But the table clearly passes the right margin leaving barely any space between the table and the edge of the page. Of course, this looks ugly and is not what i have intended.

¿Does using geometry package has anything to do with this? ¿Or is it meant to be like this?

This has been bugging me since i stared using latex! please help
thanks.

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 width longer than linewidth

Post by localghost »

In your calculations you have to take the length \arraycolsep into account. Exactly you need to subtract 2·n·\arraycolsep from the total width where n is the number of columns. Such calculations can be done by using the calc package. The following table declaration is not tested but should work as desired.

Code: Select all

\begin{longtable}[hbt]{|p{0.15\linewidth-2\arraycolsep}|p{0.35\linewidth-2\arraycolsep}|p{0.5\linewidth-2\arraycolsep}|}

Best regards and welcome to the board
Thorsten
JavierIEH
Posts: 2
Joined: Tue Nov 23, 2010 6:41 am

Table width longer than linewidth

Post by JavierIEH »

It worked perfectly, thanks.
Only one thought: Is this the only way to get the table width right? Compesating for the space that the columns take? or is there another width constant that i could use?
(like \tablewidth or smth)

I know it sounds lazy but i face this problem a lot.

Also, must i do similar compesations for other kind of floats?
thanks.

Edit: Actually i just found out a package, tabularx that does just what i needed.
You define the total table width as an arugment, then you can set special type
of columns (X) which will automatically scale to the width set.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table width longer than linewidth

Post by localghost »

If that solves the problem for you, please be so kind and mark the topic accordingly as written in Section 3 of the Board Rules (to be read before posting). Please keep that in mind for the future so that further reminders will not be necessary.
Post Reply