Hello,

Lua solution:

On Sun, 02 Sep 2012 17:59:55 +0200, Aditya Mahajan <adit...@umich.edu> wrote:

Hi,

On Edward Tufte's website, there is a discussion on zebra coloring in
tables[1]. One of the suggestion is to add a horizontal rule after every
third line or shade three lines with one background color and the
remaining three with another background color.

Is there an easy way to do this with natural TABLEs? I can do something
like:

\setupTABLE[row][1,2,3][background=color, backgroundcolor=gray]
\setupTABLE[row][7,8,9][background=color, backgroundcolor=gray]

but it requires knowing the number of lines in advance.

- it may be achieved by Lua, when the table has been defined as a Lua variable:

----
\startluacode
  tab = { { "a", "b", },
          { "c", "d", },
          { "e", "f", },
          { "g", "h", },
        }
\stopluacode

\starttext
  \startluacode
    local rows1 = {}

    for i = 1, #tab, 3 do table.insert(rows1, i) end -- Define rules here - 
setup first set of rows

    context.setupTABLE({"row"}, rows1, {background = "color", backgroundcolor = 
"gray"})

    context.bTABLE()
      for i, r in ipairs(tab) do
        context.bTR()
          for j, d in ipairs(r) do
            context.bTD()
              context(d)
            context.eTD()
          end
        context.eTR()
      end
    context.eTABLE()
  \stopluacode
\stoptext
----

Best regards,

Lukas


Aditya

[1]: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001IV

Attachment: t-Table3.mkiv
Description: Binary data

Attachment: t-Table3.pdf
Description: Adobe PDF document

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to