[NTG-context] Color a column (xtable, lua)

Henri Menke henrimenke at gmail.com
Sun Jan 27 00:26:08 CET 2019


On 1/27/19 12:08 PM, Fabrice Couvreur wrote:
> Hi,
> How to color the first column as I did for the first line ?

Stolen from Wolfgang's answer on TeX.SX.
https://tex.stackexchange.com/a/464771


\definecolor[fondpaille][c=0,m=0,y=0.2,k=0]

\startuseMPgraphic {tablebackground}
  fill OverlayBox withcolor \MPcolor{fondpaille} ;
\stopuseMPgraphic

\defineoverlay
  [tablebackground]
  [\ifnum\currentxtablerow=1
       \useMPgraphic{tablebackground}%
   \else\ifnum\currentxtablecolumn=1
       \useMPgraphic{tablebackground}%
   \fi\fi]

\setupxtable[background=tablebackground]

\starttext
\startluacode
local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }
local letters_2 = { "A", "0", "1", "1", "0", "", "", "", "", "" }
context.startxtable({"align={middle,lohi}, width=1.25cm,offset=0.8ex"})

context.startxrow()
context.startxcell({"background=color,backgroundcolor=white,frame=off"})
context("")
context.stopxcell()
for _, letter in ipairs(letters_1) do
    context.startxcell()
    context(letter) context.stopxcell()
end
context.stopxrow()

context.startxrow()
for _, letter in ipairs(letters_2) do
    context.startxcell() context(letter) context.stopxcell()
end
context.stopxrow()

for i=2,10 do
    context.startxrow()
    context.startxcell()  context(converters.convert("A",i))
    context.stopxcell()
    context.stopxrow()
end

context.stopxtable()
\stopluacode
\stoptext


> Thank you
> Fabrice
> 
> \definecolor[fondpaille][c=0,m=0,y=0.2,k=0]
> \starttext
> \startluacode
> local letters_1 = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }
> local letters_2 = { "A", "0", "1", "1", "0", "", "", "", "", "" }
> context.startxtable({"align={middle,lohi}, width=1.25cm,offset=0.8ex"})
> context.startxrow()
> context.startxcell({"background=color,backgroundcolor=white,frame=off"})
> context("") context.stopxcell()
> for _, letter in ipairs(letters_1) do
>      context.startxcell({"background=color,backgroundcolor=fondpaille"})
> context(letter) context.stopxcell()
> end
> context.stopxrow()
> context.startxrow()
> for _, letter in ipairs(letters_2) do
>      context.startxcell() context(letter) context.stopxcell()
> end
> context.stopxrow()
> for i=2,10 do
>      context.startxrow()
>      context.startxcell()  context(converters.convert("A",i))
> context.stopxcell()
>      context.stopxrow()
> end
> context.stopxtable()
> \stopluacode
> \stoptext
> 
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the Wiki!
> 
> maillist : ntg-context at ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
> 



More information about the ntg-context mailing list