21

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.

Jan
  • 5,293
benedito
  • 4,600

7 Answers7

38

You can use the chessboard package.

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

enter image description here

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,
    fieldmaskcolor=red,
    fieldcolor=red,
    emphareas={a1-a8,c1-c8,e1-e8,g1-g8},
    coloremph,
    fieldmaskcolor=white,
    fieldcolor=white,
    emphareas={b1-b8,d1-d8,f1-f8,h1-h8}]
\end{document}

enter image description here

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,
    fieldmaskcolor=red,
    fieldcolor=red,
    emphareas={a8-b7,c3-c5,e4-e7,f7-g7,g1-h3},
    coloremph,
    fieldmaskcolor=white,
    fieldcolor=white,
    emphareas={a1-b6,c6-d8,c1-d2,d3-d5,e8-h8,e1-f3,f4-h6}]
\end{document}

enter image description here

Red
  • 10,181
19

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}

enter image description here

Algorithm

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

enter image description here

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
  • @benedito from @kiss 's code: \documentclass[tikz,border=5mm]{standalone} \begin{document} \begin{tikzpicture}[brown] \foreach \x in {0,2,...,6} \foreach \y in {0,2,...,6} \fill (\x,\y) rectangle (1+\x,1+\y) rectangle (2+\x,2+\y); \draw[thick] (0,0) rectangle (8,8); \end{tikzpicture} \end{document} – Black Mild Mar 06 '23 at 03:41
18

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}

enter image description here

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

enter image description here

Gonzalo Medina
  • 505,128
  • 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
  • Unconventional Chessboard - - Gonzalo,When I compilie your update, does not appear any figure – benedito Sep 14 '13 at 18:45
  • @benedito please see my newly updated answer. – Gonzalo Medina Sep 15 '13 at 01:55
  • Gonzalo,Thanks very much. That's what I wanted. Very good. SHOW! – benedito Sep 15 '13 at 11:00
  • Unconventional Chessboard - Gonzalo,I want to separate the figures in separate files. What commands should I erase by time? – benedito Sep 16 '13 at 11:09
  • @benedito this is a new requirement; in this place, we try to keep one question per post. Please, feel free to open a follow-up question explaining your new requirement (and perhaps linking to this question to provide background). Also, since you have received some nice answers, please consider accepting the one that you consider best solved your problem. – Gonzalo Medina Sep 16 '13 at 12:11
  • 8 by 8 Board with subboards 2 by 2 alternately painted white and black. \documentclass{article} \usepackage[LSBC3,T1]{fontenc} \usepackage{chessboard} \usepackage{color} \begin{document} \setboardfontencoding{LSBC3} \setchessboard{showmover=false} \newgame \chessboard[ coloremph, fieldmaskcolor=black, fieldcolor=black, emphareas={a8-b7,e8-f7,c6-d5,g6-h5, a4-b3,e4-f3,c2-d1, g2-h1}, coloremph, fieldmaskcolor=white, fieldcolor=white, emphareas={c8-d7,g8-h7,a6-b5,e6-f5,c4-d3,g4-h3,a2-b1,e2-f1}] \end{document} – benedito Sep 16 '13 at 22:39
  • When I use this in Beamer, I get spaces between the rows. How can I fix it? – NonalcoholicBeer Aug 24 '22 at 09:24
14

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

chessboard picture

% 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) ? "white" : "black"} \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}

cmhughes
  • 100,947
3

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}
brac37
  • 133
2
\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}

enter image description here

Troy
  • 13,741
Benedito Freire
  • 795
  • 6
  • 11
2

Here's how I did it:

enter image description here

\documentclass{standalone}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture} \draw[shift={+(1,1)}] (0,0) -- (0,8) -- (8,8) -- (8,0) -- cycle; \foreach \x in {2,4,6,8} \foreach \y in {2,4,6,8} \draw[fill=black] (\x,\y) rectangle ++(1,1); \foreach \x in {1,3,5,7} \foreach \y in {1,3,5,7} \draw[fill=black] (\x,\y) rectangle ++(1,1);

\end{tikzpicture} \end{document}

Making even minor changes to the above will get you unconventional stuff. By switching the second fill to green:

enter image description here

On top of the previous change, by changing the first {2,4,6,8} to {1,3,5,7}:

enter image description here

And on top of the previous two changes, by changing the final {1,3,5,7} to {1,2,3,4}:

enter image description here

It's pretty easy to customize.

arara
  • 776