Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

up vote 5 down vote accepted

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

result

share|improve this answer
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.