Graphics, Figures & TablesProblem with table width

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ivan_hr
Posts: 18
Joined: Fri Dec 10, 2010 12:32 pm

Problem with table width

Post by ivan_hr »

Hello,

I have a problem with the width of my table. I have defined the width of my text to be 500 pt. I have defined my table to have 2 rows and 4 columns. Widths of the columns are 105pt, 145pt, 105pt and 145pt respectively. This adds up to 500pt but for some reason table turns out much wider than my text?
Does anyone know what causes this (strange) behavior and how to fix it?
Bellow is my code and attachment of my output where you clearly see that the table
is much wider than the rest of the text.

Code: Select all

\documentclass[12pt]{article}

\usepackage{latexsym,amssymb}
\usepackage{array}
\usepackage[croatian]{babel}
\usepackage[margin=1in]{geometry}

\setlength{\textwidth}{500pt}
\setlength{\parindent}{0pt}
\setlength{\textheight}{8in}
\setlength{\voffset}{-1cm}
\setlength{\hoffset}{-0.5cm}


\begin{document}

\textbf{USER DATA:}\\\\
\begin{tabular}{|b{105pt}|b{145pt}|b{105pt}|b{145pt}|}
\hline
\textbf{User e-mail:} & myname@myname.hr & \textbf{Name:} & Name Surname\\
\hline
\textbf{Date:} & 15.9.2010 &\textbf{Question ID:} & 3836127\\
\hline
\end{tabular}\\

U zadanoj kvadratnoj jednadzbi je nepoznanica $x$, dok je parametar $p$
'sporedan'. Stoga moramo malo srediti jednadzbu tako da clanove poredamo
'po redu' (najprije one koji sadrze $x^2$, pa $x$ te one bez icega): 

\end{document}
Help would be greatly appreciated. Thanks in advance.
Attachments
test2.png
test2.png (21.34 KiB) Viewed 5462 times
Last edited by ivan_hr on Wed Mar 02, 2011 11:56 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problem with table width

Post by gmedina »

Hi,

you have to take into account the horizontal separation between columns and their contents (default value: 6pt) and the width of the rules (default value: 0.4pt). For the first, you can either set the length tabcolsep to 0pt or to subtract a total of 48pt from the column widths. For the second, you need to subtract 2pt from the table width. If you don't change tabcolsep, then you can only use 450pt (500pt-48pt-2pt) as the total width for the table.

As a side note, you could use the geometry package to change the page layout instead of manualy changing \textwidth, \textheight, etc.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
ivan_hr
Posts: 18
Joined: Fri Dec 10, 2010 12:32 pm

Re: Problem with table width

Post by ivan_hr »

Thanks a lot for your nice explanation gmedina. That has solved my problem :)
vaman
Posts: 17
Joined: Wed Oct 09, 2019 5:51 am

Problem with table width

Post by vaman »

\documentclass[12pt]{article}
\setlength{\textwidth}{15cm}
\setlength{\parindent}{0pt}
\setlength{\textheight}{8in}
\setlength{\voffset}{-1cm}
\setlength{\hoffset}{-0.5cm}
\begin{document}

{\bf USER DATA:}

\vspace{0.5cm}


\begin{tabular}{|p{3cm}|p{4cm}|p{3cm}|p{3cm}|}\hline

\textbf{User e-mail:} & myname@myname.hr & \textbf{Name:} & Name Surname\\
\hline
\textbf{Date:} & 15.9.2010 &{\bf Question ID:} & 3836127\\
\hline
\end{tabular}\\

\vspace{0.25cm}


U zadanoj kvadratnoj jednadzbi je nepoznanica $x$, dok je parametar $p$
'sporedan'. Stoga moramo malo srediti jednadzbu tako da clanove poredamo
'po redu' (najprije one koji sadrze $x^2$, pa $x$ te one bez icega):

\end{document}

I have rearranged page size and also column size in cm. Please try this.
User avatar
Ijon Tichy
Posts: 640
Joined: Mon Dec 24, 2018 10:12 am

Problem with table width

Post by Ijon Tichy »

If you continue riding dead horses, it would be nice if you would at least mark your code as code. Only correctly marked code can be tested in the online compiler. And not marked code could be broken by the formatting of the forum software.

BTW: \bf is a deprecated font command. The \textbf of the original code is a better solution. See fntguide for more information about the preferred font commands since LaTeX2e.

BTW: It does not make much sense to load package geometry and not use it but setup several page parameters without using geometry. The recommended solution to change the page margins etc. is to use a the options of geometry.
Sorry, but I can no longer participate here as the administrator is trampling on my wishes on one of his other platforms. :cry:
Post Reply