Graphics, Figures & Tablesauto-size table width to make use of all space available

Information and discussion about graphics, figures & tables in LaTeX documents.
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

auto-size table width to make use of all space available

Post by ptrcao »

goal: auto-size table width to make use of all space available

problem: table is width-wise, very long and runs off the page

do not want to manually set column width for columns. too much thinking and effort. want an automatic solution.
Last edited by ptrcao on Mon Feb 21, 2011 12:13 pm, edited 1 time in total.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)

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
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

auto-size table width to make use of all space available

Post by localghost »

Try the tabularx package.


Thorsten
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Re: auto-size table width to make use of all space available

Post by ptrcao »

To use the tabularx package in the way I want, I have to know what the default width of the text is across the page, do you know?

As in, how do I tell tabularx just to use the full width of a line of text for the table? Use all the space available to it without going outside my page's margin.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

auto-size table width to make use of all space available

Post by localghost »

ptrcao wrote:To use the tabularx package in the way I want, I have to know what the default width of the text is across the page, do you know? […]
There is a length \textwidth which should be self-explanatory. More flexible is the length \linewidth. Just try and see what happens.
ptrcao wrote:[…] As in, how do I tell tabularx just to use the full width of a line of text for the table? Use all the space available to it without running off the page.
Read the package manual. That's what it's made for. Either follow the link in my last reply or open a command line for access on your local machine.

Code: Select all

texdoc tabularx
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

Re: auto-size table width to make use of all space available

Post by ptrcao »

Thank you for the \linewidth tip - I wouldn't have figured that out.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

auto-size table width to make use of all space available

Post by ptrcao »

Um...there is no way to text-align the contents of the columns with the specification {X X X} used in

Code: Select all

\begin{tabularx}{1\linewidth}{X X X X X}
Some help on this please?
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: auto-size table width to make use of all space available

Post by localghost »

I'm afraid I can't follow you. Please describe more precise what you want to do and how the text alignment shall look like.
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

auto-size table width to make use of all space available

Post by ptrcao »

This is my table:
table.gif
table.gif (48.16 KiB) Viewed 31753 times
You'll see that everything is left-aligned by default.
Suppose I want to center the text contents of columns.
Normally this is done as

Code: Select all

{c c c c c}
or

Code: Select all

{m{width} m{width} m{width} m{width} m{width}}
However, here we are using

Code: Select all

{X X X X X}
There is no optional argument which I can use to center the text inside columns.
I would like to center the contents nonetheless. Can you suggest how?

---------

PS. While you see my table in the image, can you suggest a solution also for the ugly situation with:

Lyx Stand-
alone

The combination of excessive spacing and hyphenation gives a really ugly look.

Edit: I think the solution would involve disabling hyphenation and disabling justified text, but I have no idea how to do this inside a table.

---------

Thank you.
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

auto-size table width to make use of all space available

Post by localghost »

It can't do any harm to add at least the code of the table. A complete but minimal example would be better [1]. I don't feel like writing the table from scratch for testing possible solutions.

[1] View topic: Avoidable mistakes
ptrcao
Posts: 88
Joined: Sun Dec 05, 2010 3:26 am

auto-size table width to make use of all space available

Post by ptrcao »

No problem. The minimal example is as follows. I've included the offending line also for the other problem with excessive spacing and hyphenation.

Code: Select all

\documentclass[12pt]{article}
\usepackage{booktabs} %for top, middle and bottomline
\usepackage{array} %enables, for table columns, m{width} and b{width} (only p{width is available without it})
\usepackage{tabularx} %for automation of column widths so that the table spans the width defined by textwidth and linewidth

\begin{document}

{\small
\begin{table}[h]
\caption{Comparison of \LaTeX-based or \LaTeX-supporting Equation Editors} 
\label{editor-comparison}
\centering
\begin{tabularx}{1\linewidth}{X X X X X}
\toprule
 Editor (Type) & Edited as & Previewed as & Inserted as \\ 
\toprule
LyX (Standalone) & WYSIWYG inline or button-facilitated mark-up & WYSIWYG inline & WYSIWYG inline \\ 
\bottomrule
\end{tabularx}
\end{table}
}

\end{document}
OS info: Win XP | Debian 6.0 | Ubuntu 10.04
Latex editor of choice: TexWorks (for dual view feature)
Post Reply