To draw a chessboard

How to draw a chessboard with unconventional house's colors?

I can draw alternately black and white house. But, I can't draw alternating column colors black and white.

• Hi, welcome to TeX.SX. If you have some code producing a chessboard, and you only want to change the colours, it would be nice if you added that code in a minimal example (with documentclass and any necessary packages) to your question. You've gotten a couple of answers already, but in general it is always nice if you add such examples. Makes it easier for those trying to help. – Torbjørn T. Sep 14 '13 at 16:41
• I updated my answer – Red Sep 15 '13 at 12:09
• Since you have some responses below that seem to answer your question, please consider marking one of them as ‘Accepted’ by clicking on the tickmark below their vote count (see How do you accept an answer?). This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). It's part of this site's idea to identify good questions and answers through upvotes and acceptance of answers. – jubobs Dec 2 '13 at 17:27

You can use the chessboard package.

\documentclass{article}
\usepackage{chessboard}
\usepackage{skak}
\begin{document}
\setchessboard{showmover=false}
\newgame
\chessboard
\end{document}


And you can personalize your chessboard as you want. For example (if I understand correctly what you want to achieve):

\documentclass{article}
\usepackage[LSBC3,T1]{fontenc}
\usepackage{chessboard}
\usepackage{skak}
\usepackage{color}
\begin{document}
\setboardfontencoding{LSBC3}
\setchessboard{showmover=false}
\newgame
\chessboard[
coloremph,
fieldcolor=red,
emphareas={a1-a8,c1-c8,e1-e8,g1-g8},
coloremph,
fieldcolor=white,
emphareas={b1-b8,d1-d8,f1-f8,h1-h8}]
\end{document}


or more strange configurations:

\documentclass{article}
\usepackage[LSBC3,T1]{fontenc}
\usepackage{chessboard}
\usepackage{skak}
\usepackage{color}
\begin{document}
\setboardfontencoding{LSBC3}
\setchessboard{showmover=false}
\newgame
\chessboard[
coloremph,
fieldcolor=red,
emphareas={a8-b7,c3-c5,e4-e7,f7-g7,g1-h3},
coloremph,
fieldcolor=white,
emphareas={a1-b6,c6-d8,c1-d2,d3-d5,e8-h8,e1-f3,f4-h6}]
\end{document}


With PSTricks

\documentclass[pstricks]{standalone}
\psset{linecolor=brown}
\begin{document}
\begin{pspicture}(8,8)
\multips(0,0)(0,2){4}{%
\multips(0,0)(2,0){4}{%
\psframe*(1,1)\psframe*(1,1)(2,2)}}
\end{pspicture}
\end{document}


Algorithm

The following animation shows the algorithm used to generate the board.

Without PSTricks

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}[x=1cm]
\foreach \y in {0,2,...,6}{
\foreach \x in {0,2,...,6}{
\fill (\x,\y) rectangle (1+\x,1+\y) rectangle (2+\x,2+\y);}}
\end{tikzpicture}
\end{document}


As the output is visually identical, I think I don't need to re-show it again.

• Can I to change black color to brown color? – benedito Sep 14 '13 at 18:03

Since the question contains the text "house's color unconventional", I assumed you need control over the colors to be applied and over the size and number of rows/columns of the chessboard. The following allows you to do that; you can easily draw a conventional chessboard, but you can also easily produce unconventional patterns as requested.

\documentclass{article}
\usepackage[dvipsnames]{xcolor}
\usepackage{keyval}

\def\Side{\ChessSide}
\newcommand\ChessBoxA{%
{\fboxsep=0pt\fbox{\color{\ChessColori}\rule{\Side}{\Side}}}}
\newcommand\ChessBoxB{%
{\fboxsep=0pt\fbox{\color{\ChessColorii}\rule{\Side}{\Side}}}}

\makeatletter
\newcommand\Row[1]{%
\par\nobreak\nointerlineskip\vskip-\fboxrule%
\@tfor\@tempa:=#1 \do {\csname ChessBox\@tempa\endcsname\kern-\fboxrule}}
\define@key{chessB}{side}{\def\ChessSide{#1}}
\define@key{chessB}{colori}{\def\ChessColori{#1}}
\define@key{chessB}{colorii}{\def\ChessColorii{#1}}
\setkeys{chessB}{
side=1.5em,
colori=black!70,
colorii=white}
\makeatother

\newcommand\Conventional[1][]{%
\begin{Chessboard}[#1]
\Row{B,A,B,A,B,A,B,A}
\Row{A,B,A,B,A,B,A.B}
\Row{B,A,B,A,B,A,B,A}
\Row{A,B,A,B,A,B,A.B}
\Row{B,A,B,A,B,A,B,A}
\Row{A,B,A,B,A,B,A.B}
\Row{B,A,B,A,B,A,B,A}
\Row{A,B,A,B,A,B,A.B}
\end{Chessboard}%
}

\newenvironment{Chessboard}[1][]
{\setkeys{chessB}{#1}%
\par\medskip\setlength\parindent{0pt}}
{\par\medskip}

\begin{document}

\Conventional

\Conventional[side=10pt,colori=Bittersweet]

\begin{Chessboard}
\Row{B,A,B,A,A,B}
\Row{A,A,B,A,B,B}
\Row{B,A,B,A,B,B}
\Row{A,A,B,B,A,B}
\Row{B,A,B,A,B,B}
\Row{A,A,A,A,B,A}
\end{Chessboard}

\begin{Chessboard}[side=0.8em,colori=MidnightBlue,colorii=Dandelion]
\Row{A,A,B,B}
\Row{A,A,B,B}
\Row{B,B,A,A}
\Row{B,B,A,A}
\end{Chessboard}

\begin{Chessboard}[side=1.2cm,colori=Maroon,colorii=ForestGreen]
\Row{A,A,B,B,A}
\Row{A,B,B,B,A}
\Row{A,B,B,A,A}
\Row{B,B,A,A,B}
\Row{B,B,B,A,B}
\end{Chessboard}

\end{document}


In the example, a simple key=value mechanism allows to control the side of each square, as well as the two colors used to produce the pattern. The keys are side (default=1.5em), colori (default=black!70), and colorii (default=white).

\Conventional draws a conventional chessboard; using an optional argument you can pass the options to this conventional chessboard.

The Chessboard environment allows you to have different patterns; inside this environment you use the \Row command to specify each row; the mandatory argument is a comma separated list of characters "A" and "B" which correspond to the colors to be used in that row; for example, with the default settings,

\begin{Chessboard}
\Row{B,A,B,A,A,B}
\end{Chessboard}


produces

• mmm maybe you understand better than me the question :-) – Red Sep 14 '13 at 16:38
• Thanks. One question: How a draw a chessboard with color alternately black and white square 2 by 2? – benedito Sep 14 '13 at 17:08
• @benedito Please see my updated answer. – Gonzalo Medina Sep 14 '13 at 17:14
• @benedito also, please consider editing the title of your question so that it is clear that you are looking for unconventional cheesboard-like designs. – Gonzalo Medina Sep 14 '13 at 17:26
• Unconventional Cheessboard (8 by 8) - I would also like to see how to make a board with only two white houses, no neighbours, and black color on the rest. – benedito Sep 14 '13 at 18:33

A simplistic tikz approach using Using \pgfmathparse and \ifnum for a TikZ checkerboard

% arara: pdflatex
% !arara: indent: {overwrite: yes}
\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}[x=1cm]
\foreach \x in {0,...,7} \foreach \y in {0,...,7}
{
\pgfmathparse{mod(\x+\y,2) ? "black" : "white"}
\edef\colour{\pgfmathresult}
\path[fill=\colour] (\x,\y) rectangle ++ (1,1);
}
\draw (0,0)--(0,8)--(8,8)--(8,0)--cycle;
\end{tikzpicture}

\end{document}

• The last draw should be ended by cycle to make the bottom left corner properly fused. – kiss my armpit Sep 15 '13 at 3:12
• to the downvoter, please always leave a comment- it will help me improve the answer – cmhughes Sep 20 '13 at 16:05
• @cmhughes the lower left square should be dark, might explain the downvote. – user45638 Feb 7 '14 at 8:13

If you draw all square edges with a single loop, you can just instruct to color the chessboard: the squares to be colored will be selected automatically.

\begin{center}
\begin{tikzpicture}[x=6mm,y=6mm]
\draw[fill=black!30,even odd rule] (0,0)
foreach \n in {1,2,3,4} { -- ++ (8,0) -- ++ (0,1) -- ++ (-8,0) -- ++ (0,1) } -- (8,8)
foreach \n in {1,2,3,4} { -- ++ (0,-8) -- ++ (-1,0) -- ++ (0,8) -- ++ (-1,0) } -- cycle
foreach[count=\n] \m in {A,B,...,H} { (-0.4,\n-0.5) node {\n} (\n-0.5,-0.5) node {\m} };
\end{tikzpicture}
\end{center}

• could make this fully compilable, please? everyone else, who answered, did as well. thanks in advance. – naphaneal May 15 '18 at 10:25
\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[x=6mm,y=6mm]
\draw[fill=black!30,even odd rule] (0,0)
foreach \n in {1,2,3,4} { -- ++ (8,0) -- ++ (0,1) -- ++ (-8,0) -- ++ (0,1) } -- (8,8)

foreach \n in {1,2,3,4} { -- ++ (0,-8) -- ++ (-1,0) -- ++ (0,8) -- ++ (-1,0) } -- cycle

foreach[count=\n] \m in {a,b,...,h} { (-0.4,\n-0.5) node {\n} (\n-0.5,-0.5) node {\m} };

\end{tikzpicture}
\end{document}


• It looks like you've got two separate accounts, which means you cannot edit your original post or leave comments. The Stack Exchange staff can merge them together for you. – user36296 May 15 '18 at 19:57