5

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

Name    Email
John    [email protected]
Bill    [email protected]
Tim     [email protected]

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?

1

1 Answer 1

5

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, [email protected]
  Bill, [email protected]
  Tim , [email protected]
\stopNaturalTable

\starttabulate [|p(3cm)r|l|]
  \NC Name \NC Email                \AR
  \NC John \NC [email protected]   \AR
  \NC Bill \NC [email protected] \AR
  \NC Tim  \NC [email protected]  \AR
\stoptabulate


\stoptext

result

3
  • by the way, how can I center the table created by \starttabulate and \stoptabulate? I have tried \startalignment[middle] and \stopalignment, but nothing happened.
    – yanpengl
    Apr 16, 2013 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?
    – yanpengl
    Apr 16, 2013 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, 2013 at 6:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .