# Set the width of every columns of a table in ConTeXt

Sometimes, I need such a table whose column widths should be equal with each other. Here is an example:

Name    Email
John    john1989@gmail.com
Bill    bill1990@outlook.com
Tim     tim1995@hotmail.com


The Name Column should flushed right and the Email Column should be flushed left. Of course, each column has the same width.

I think this requirement can be achieved by the \starttable and \stoptable, but how to combine the l or r with the required width?

-
Use \starttable[|lw(4cm)r|lw(7cm)]. A small list of references are given here: tex.stackexchange.com/questions/2839/… –  Marco Daniel Apr 15 '13 at 17:01

The \starttable syntax is deprecated and should thus be avoided for new documents. That's why I present a solution using natural tables, also called HTML tables. Since natural tables are very verbose they can be best combinded with the database module. That allows very easy and readable syntax, but is less flexible. It depends on your requirements if the database module makes sense in this case. The natural table setup is the same in both cases.

For more simple tasks the tabulate tables might be sufficient.

\usemodule [database]

\defineseparatedlist
[NaturalTable]
[separator=comma, %% not necessary, already the default
before=\bTABLE, after=\eTABLE,
first=\bTR, last=\eTR,
left=\bTD, right=\eTD,
setups=s:NaturalTable]

\startsetups [s:NaturalTable]
\setupTABLE              [frame=off, distance=5mm]
\setupTABLE [column] [1] [width=2cm, align=flushright]
\setupTABLE [row]    [1] [style=bold]
\stopsetups

\starttext

\startNaturalTable
Name, Email
John, john1989@gmail.com
Bill, bill1990@outlook.com
Tim , tim1995@hotmail.com
\stopNaturalTable

\starttabulate [|p(3cm)r|l|]
\NC Name \NC Email                \AR
\NC John \NC john1989@gmail.com   \AR
\NC Bill \NC bill1990@outlook.com \AR
\NC Tim  \NC tim1995@hotmail.com  \AR
\stoptabulate

\stoptext


-
thanks, Marco. Let me learn the tabulate first. –  Timothy Li Apr 16 '13 at 1:47
by the way, how can I center the table created by \starttabulate and \stoptabulate? I have tried \startalignment[middle] and \stopalignment, but nothing happened. –  Timothy Li Apr 16 '13 at 2:36
I use the plain TeX method \hbox to\hsize{\vbox{\starttabulate...\stoptabulate}}. This won't be broken across pages, is there another way by which the table can span pages? –  Timothy Li Apr 16 '13 at 2:55
That's tricky with tabulate. The easiest (but ugly) way is to use something like \starttabulate[|p(.4\textwidth)|l|]. For a more automatic solution see Philipps \centertabulation macro. –  Marco Apr 16 '13 at 6:50