Setting options for every n-th row in natural TABLEs
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. Aditya [1]: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001IV
Am 02.09.2012 um 17:59 schrieb Aditya Mahajan
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.
Aditya
[1]: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001IV
Natural tables have “odd” and “even” keywords for \setupTABLE but none in the way you like it. What I would do is to use a overlay in combination with metapost to create the background but there is no global register to access the current column/row of a cell, e.g. \currenttablecolumn (this name is already used by tables) and \currenttablerow. Wolfgang
On Sun, 2 Sep 2012, Wolfgang Schuster wrote:
Am 02.09.2012 um 17:59 schrieb Aditya Mahajan
: 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.
Aditya
[1]: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001IV
Natural tables have “odd” and “even” keywords for \setupTABLE but none in the way you like it.
Well, I can always change what odd and even means :) (I also realized that odd and even are just dummy values. I can change them to anything, and can in fact even turn \v!oddeven to a switch statement that returns multiple values) \unprotect \def\redefineoddeven% HACK {\def\v!oddeven##1% Return odd if in set 1-3, 7-9, etc. and even otherwise {\ctxcommand{doifelse(math.mod(##1-1,6) < 3)}\v!odd\v!even}} \protect \startsetups zebra:three \redefineoddeven \setupTABLE[frame=off,background=color] \setupTABLE[row][odd][backgroundcolor=blue] \setupTABLE[row][even][backgroundcolor=red] \stopsetups \starttext \startTABLE[setups={zebra:three}] \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \NC A \NC B \NC C \NC \NR \stopTABLE \stoptext
What I would do is to use a overlay in combination with metapost to create the background but there is no global register to access the current column/row of a cell, e.g. \currenttablecolumn (this name is already used by tables) and \currenttablerow.
Thanks for the hint. It is relatively easy to access the local counter for a cell, and changing background colors dependon the current row works well. \defineconversion [triadcolors] [blue,blue,blue,red,red,red] \startsetups zebra:three \setupTABLE[frame=off,background=color] \setupTABLE[row][backgroundcolor={\convertnumber{triadcolors}{\getvalue{m_tabl_ntb_positive_row}}}] \stopsetups If I need rules, I guess I can explicitly check for the value of \m_tabl_ntb_postive_pow inside an overlay. Thanks, Aditya
Am 03.09.2012 um 02:39 schrieb Aditya Mahajan
If I need rules, I guess I can explicitly check for the value of \m_tabl_ntb_postive_pow inside an overlay.
This is a internal register and not meant for users, what we need is a real user level command to access the row and column counter from TeX or Lua. Wolfgang
Natural tables have “odd” and “even” keywords for \setupTABLE but none in the way you like it. What I would do is to use a overlay in combination with metapost to create the background but there is no global register to access the current column/row of a cell, e.g. \currenttablecolumn (this name is already used by tables) and \currenttablerow.
... Maybe \currentTABLEcolumn (no collision with tables' \currenttablecolumn) and \currentTABLErow could be defined for this purpose. Lukas -- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
On Mon, 3 Sep 2012, Procházka Lukáš Ing. - Pontex s. r. o. wrote:
Natural tables have “odd” and “even” keywords for \setupTABLE but none in the way you like it. What I would do is to use a overlay in combination with metapost to create the background but there is no global register to access the current column/row of a cell, e.g. \currenttablecolumn (this name is already used by tables) and \currenttablerow.
... Maybe \currentTABLEcolumn (no collision with tables' \currenttablecolumn) and \currentTABLErow could be defined for this purpose.
I agree. In addition, \currentTABLEheaderrow, \currentTABLEheadercolumn, \currentTABLEfooterrow, \currentTABLEfootercolumn, and the \max... version of all of these are also useful at the user level. Aditya
On 2-9-2012 20:58, Wolfgang Schuster wrote:
Am 02.09.2012 um 17:59 schrieb Aditya Mahajan
: 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.
Aditya
[1]: http://www.edwardtufte.com/bboard/q-and-a-fetch-msg?msg_id=0001IV
Natural tables have “odd” and “even” keywords for \setupTABLE but none in the way you like it. What I would do is to use a overlay in combination with metapost to create the background but there is no global register to access the current column/row of a cell, e.g. \currenttablecolumn (this name is already used by tables) and \currenttablerow.
I've added 4 status macros: \starttext \bTABLE \bTR \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \eTR \bTR \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \eTR \eTABLE \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com | www.pragma-pod.nl -----------------------------------------------------------------
On Tue, 4 Sep 2012, Hans Hagen wrote:
I've added 4 status macros:
\starttext
\bTABLE \bTR \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \eTR \bTR \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \bTD (\currentTABLErow,\currentTABLEcolumn,\nofTABLErows,\nofTABLEcolumns) \eTD \eTR \eTABLE
\stoptext
Thanks! Aditya
http://wiki.contextgarden.net/Command/currentTABLErow http://wiki.contextgarden.net/Command/currentTABLEcolumn http://wiki.contextgarden.net/Command/nofTABLErows http://wiki.contextgarden.net/Command/nofTABLEcolumns A bit of cutting, a bit of pasting ... the six-year-old in me is happy. :-) --Sietse
... Thanks Hans for implementation and Sietse for wikifying.
BTW: Wouldn't be better to enclose ConText source on wiki into <context mode=mkiv source=yes> rather than <texcode> even if the source doesn't compile due to wiki-ConTeXt oldness?
I believe one day the wiki-ConTeXt engine will be updated and so all examples with the current result "(context error, something is wrong with the input)" will work.
Otherwise, inside <texcode> element, the result will never appear, which seems to me to be pity...
Best regards,
Lukas
On Tue, 04 Sep 2012 19:33:20 +0200, Sietse Brouwer
http://wiki.contextgarden.net/Command/currentTABLErow http://wiki.contextgarden.net/Command/currentTABLEcolumn http://wiki.contextgarden.net/Command/nofTABLErows http://wiki.contextgarden.net/Command/nofTABLEcolumns
A bit of cutting, a bit of pasting ... the six-year-old in me is happy. :-)
--Sietse
-- Ing. Lukáš Procházka [mailto:LPr@pontex.cz] Pontex s. r. o. [mailto:pontex@pontex.cz] [http://www.pontex.cz] Bezová 1658 147 14 Praha 4 Tel: +420 244 062 238 Fax: +420 244 461 038
Hello,
Lua solution:
On Sun, 02 Sep 2012 17:59:55 +0200, Aditya Mahajan
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
On Sun, 2 Sep 2012, Procházka Lukáš wrote:
On Sun, 02 Sep 2012 17:59:55 +0200, Aditya Mahajan
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:
Thanks. This is useful when reading data from a file. Aditya
participants (6)
-
Aditya Mahajan
-
Hans Hagen
-
Procházka Lukáš
-
Procházka Lukáš Ing. - Pontex s. r. o.
-
Sietse Brouwer
-
Wolfgang Schuster