Table, stretchable column and row entry 

Solution / Conclusion 

to make a ruber-lengthed column to stretch to the end:

\usepackage{tabularx} % in the preamble

Example 2. ..

\begin{tabularx}{\textwidth}{crllcX}

or whatever: the X column is a p-like column with implicit (i.e., stretchable) width.

Goal 

Newsgroups:  comp.text.tex
Date:        29 Mar 2004 18:28:57 GMT
> I've got two questions on table.
>
> - How to make my last column of the table stretch to the end,
>   using the rest of the line space?

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=fixwidtab

> - Does the table entry has to be on one line?
>
> About the 2nd question, here is my test file:
> I get the following error:
>
> ! LaTeX Error: Something's wrong--perhaps a missing \item.
>
> See the LaTeX manual or LaTeX Companion for explanation.
> Type  H <return>  for immediate help.
>  ...
>
> l.20 ... 4 & \centering 5 & \centering 6 \\ \hline
>
> What's wrong?

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tabcellalign

Ulrike Fischer

Goal 

> > http://www.tex.ac.uk/cgi-bin/texfaq2html?label=fixwidtab[]
>
>hmm, after reading it several times, I think you meant to suggest the
>tabulary package:
>
>,-----
>| The tabulary package (by the same author) provides a way of
>| "balancing" the space taken by the columns of a table. The package
>| defines column specifications C, L, R and J, giving, respectively,
>| centred, left, right and fully-justified versions of space-sharing
>| columns. The package examines how long each column would be
>| "naturally" (i.e., on a piece of paper of unlimited width), and
>| allocates space to each column accordingly.
>`-----

actually, no. tabulary shares out the space between several variable-width columns, in an equitable way; tabularx is quicker and does an equally good job if there's only one stretchable column..

>However, I still don't know how to make a ruber-lengthed column to stretch
>to the end... Could someone show me how please?
\begin{tabularx}{\textwidth}{crllcX}

or whatever: the X column is a p-like column with implicit (i.e., stretchable) width. i thought it was obvious — plainly need more examples in the faq answer (noted in list of things-to-do).

Robin

Fixed-width tables 

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=fixwidtab

There are two basic techniques for making fixed-width tables in LaTeX: you can make the gaps between the columns stretch, or you can stretch particular cells in the table.

the tabular* environment 

Basic LaTeX can make the gaps stretch: the tabular* environment takes an extra argument (before the clpr layout one) which takes a length specification: you can say things like "15cm" or "\columnwidth" here. You must also have an \extracolsep command in the clpr layout argument, inside an @ directive. So, for example, one might have

\begin{tabular*}{\columnwidth}{@{\extracolsep{\fill}}lllr}

The \extracolsep applies to all inter-column gaps to its right as well; if original.

The tabularx package 

The tabularx package defines an extra clpr column specification, X; X columns behave as p columns which expand to fill the space available. If there's more than one X column in a table, the spare space is distributed between them.

The tabulary package 

The tabulary package (by the same author) provides a way of "balancing" the space taken by the columns of a table. The package defines column specifications C, L, R and J, giving, respectively, centred, left, right and fully-justified versions of space-sharing columns. The package examines how long each column would be "naturally" (i.e., on a piece of paper of unlimited width), and allocates space to each column accordingly. There are "sanity checks" so that really large entries don't cause everything else to collapse into nothingness (there's a "maximum width" that any column can exert), and so that tiny entries can't get smaller than a specified minimum. Of course, all this work means that the package has to typeset each row several times, so things that leave "side-effects" (for example, a counter used to produce a row-number somewhere) are inevitably unreliable, and should not even be tried.

The ltxtable combines the features of the longtable and tabularx packages: it's important to read the documentation, since usage is distinctly odd.

How to alter the alignment of tabular cells 

http://www.tex.ac.uk/cgi-bin/texfaq2html?label=tabcellalign

One often needs to alter the alignment of a tabular p ('paragraph') cell, but problems at the end of a table row are common. If we have a p cell that looks like

... & \centering blah ... \\

one is liable to encounter errors that complain about a "misplaced \noalign" (or the like). The problem is that the command \\ means different things in different circumstances: the tabular environment switches the meaning to a value for use in the table, and \centering, \flushright and \flushleft all change the meaning to something incompatible. Note that the problem only arises in the last cell of a row: since each cell is set into a box, its settings are lost at the & (or \\) that terminates it.

The simple (old) solution is to preserve the meaning of \\:

\def\PBS#1{\let\temp=\\%
  #1%
  \let\\=\temp
}

which one uses as:

... & \PBS\centering blah ... \\

(for example).

The technique using \PBS was developed in the days of LaTeX 2.09 because the actual value of \\ that the tabular environment used was only available as an internal command. Nowadays, the value is a public command, and you can in principle use it explicitly:

... & \centering blah ... \tabularnewline

but the old trick has the advantage of extreme compactness.

The \PBS trick also serves well in array package "field format" preamble specifications:

\begin{tabular}{... >{\PBS\centering}p{50mm}} ...