# Colorate table as Chess board way

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?

Thanks!

• 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? 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 :/. Mar 12 '17 at 15:22
• @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
• @cfr haha Ok dude, be happy please. Greetings. 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]
\stopsetups

\starttext

\subject{Short table}
\startTABLE[setups=chess]
\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
\stopTABLE

\subject{Long table, generated in lua}
\startluacode
context.bTABLE{setups="chess"}
for row = 0, 9 do
context.bTR()
for col = 1, 10 do
context.bTD() context(row*10 + col) context.eTD()
end
context.eTR()
end
context.eTABLE()
\stopluacode
\stoptext


which gives

• What a beautiful code, I didn't know about existence of "ConTeXt", so double thank you ! 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.

\documentclass{article}
\usepackage[table,xcdraw]{xcolor}
\begin{document}
\begin{table}
\centering
\begin{tabular}{
>{\columncolor[HTML]{9B9B9B}}l
>{\columncolor[HTML]{FFFFFF}}l
>{\columncolor[HTML]{9B9B9B}}l
>{\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}
\end{tabular}
\end{table}
\end{document}