I made a Sieve of Erastothenes, but I'd like to colour it as a chessboard (well, not black and white but gray and white). Someone know a trick with tex to colour it automatically?


  • 2
    You'll get more and better answers if you give us a minimal working example that has your table to start with. I assume you don't want a chessboard coloring, but to color the primes gray and the composites white, yes?
    – Teepeemm
    Mar 10 '17 at 15:54
  • @Teepeemm I know it but I did a normal table, think about it... it's a horrible tex code :/.
    – UnPerrito
    Mar 12 '17 at 15:22
  • 2
    @UnPerrito Think about it ... you are asking people to start from scratch, not even providing the shell. And you are limited to helpers who either know what the hell you're talking about or are prepared to first research that and then start from scratch, if the question turns out to be interesting and something they can help with. Personally, I want to know what makes it Erastothenes' sieve and not somebody else's. Does it need a label designating the owner? Is it a small one for straining tea or a large one for rice?
    – cfr
    Mar 12 '17 at 23:09
  • 1
    @cfr haha Ok dude, be happy please. Greetings.
    – UnPerrito
    Mar 20 '17 at 14:13

In ConTeXt, this is relatively simple to do using Natural Tables

\startsetups chess
  \setupTABLE[each][each][width=2em, height=2em, align={middle,lohi}] 
  \setupTABLE[even][even][background=color, backgroundcolor=gray]
  \setupTABLE[odd] [odd] [background=color, backgroundcolor=gray]


\subject{Short table}
   \NC 1  \NC 2  \NC 3  \NC 4  \NC \NR
   \NC 5  \NC 6  \NC 7  \NC 8  \NC \NR
   \NC 9  \NC 10 \NC 11 \NC 12 \NC \NR
   \NC 13 \NC 14 \NC 15 \NC 16 \NC \NR

\subject{Long table, generated in lua}
    for row = 0, 9 do 
      for col = 1, 10 do 
        context.bTD() context(row*10 + col) context.eTD()

which gives

enter image description here

  • What a beautiful code, I didn't know about existence of "ConTeXt", so double thank you !
    – UnPerrito
    Mar 12 '17 at 15:24

I don't know what is a Sieve of Erastothene means, so I think this could be used to get what you need.

>{\columncolor[HTML]{FFFFFF}}l }
                     &                          &                          &                             \\
\cellcolor[HTML]{FFFFFF} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]   {FFFFFF} & \cellcolor[HTML]{9B9B9B} \\
                     &                          &                          &                          \\
\cellcolor[HTML]{FFFFFF} & \cellcolor[HTML]{9B9B9B} & \cellcolor[HTML]{FFFFFF} & \cellcolor[HTML]{9B9B9B}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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