ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
From: "Procházka Lukáš" <LPr@pontex.cz>
To: "mailing list for ConTeXt users" <ntg-context@ntg.nl>
Subject: Re: Setting options for every n-th row in natural TABLEs
Date: Sun, 02 Sep 2012 21:56:35 +0200	[thread overview]
Message-ID: <op.wj0xold5dk1lar@lk-2008-nbk> (raw)
In-Reply-To: <alpine.LNX.2.02.1209021106370.28173@ybpnyubfg.ybpnyqbznva>

[-- Attachment #1: Type: text/plain, Size: 1531 bytes --]

Hello,

Lua solution:

On Sun, 02 Sep 2012 17:59:55 +0200, Aditya Mahajan <adityam@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 #2: t-Table3.mkiv --]
[-- Type: application/octet-stream, Size: 693 bytes --]

\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 first 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

[-- Attachment #3: t-Table3.pdf --]
[-- Type: application/pdf, Size: 5999 bytes --]

[-- Attachment #4: Type: text/plain, Size: 485 bytes --]

___________________________________________________________________________________
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
___________________________________________________________________________________

  parent reply	other threads:[~2012-09-02 19:56 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-02 15:59 Aditya Mahajan
2012-09-02 18:58 ` Wolfgang Schuster
2012-09-03  0:39   ` Aditya Mahajan
2012-09-03  4:37     ` Wolfgang Schuster
2012-09-03  6:14   ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-09-03 14:40     ` Aditya Mahajan
2012-09-04 14:34   ` Hans Hagen
2012-09-04 15:21     ` Aditya Mahajan
2012-09-04 17:33       ` Sietse Brouwer
2012-09-05  7:01         ` Procházka Lukáš Ing. - Pontex s. r. o.
2012-09-02 19:56 ` Procházka Lukáš [this message]
2012-09-03  0:41   ` Aditya Mahajan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.wj0xold5dk1lar@lk-2008-nbk \
    --to=lpr@pontex.cz \
    --cc=ntg-context@ntg.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).