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.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityHow 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.
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,
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}
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}
\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.
\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.
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
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}
draw
should be ended by cycle
to make the bottom left corner properly fused.
– kiss my armpit
Sep 15 '13 at 3:12
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}
\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}