2

How can I produce squares like this of arbritary sizes? colored squares

I have been looking at skak, but cannot find an example that is not producing entire chessboards.

I know I have seen this somewhere before, but I cannot remember the words that describe this in english.

Crumar
  • 65

1 Answers1

2

Unless you are using something specific to chess I would use tikz rather than skak. The basic idea of tikz is to use \draw commands with xy-coordinates. Here is one way to produce shaded 2x2 squares:

\documentclass{article}
\usepackage{tikz}

% \BackSquares{ list of south west coordinates of squares to fill }
\newcommand\BlackSquares[1]{
  \begin{tikzpicture}
    \draw[ultra thick](0,0) rectangle (2,2);
    \draw[ultra thick](0,1)--(2,1);
    \draw[ultra thick](1,0)--(1,2);
    \foreach \sq in {#1} {\draw[fill=black]\sq rectangle ++(1,1);}
  \end{tikzpicture}
}

\begin{document}
  \BlackSquares{{(0,0)},{(1,0)}}
  \BlackSquares{{(0,0)},{(0,1)}}
  \BlackSquares{{(0,0)},{(1,1)}}
  \BlackSquares{{(1,0)},{(0,1)}}
\end{document}

This MWE produces:enter image description here

  • Great, thank you. I just always struggle when it comes to tikz and it ends up with trial and error. but that looks pretty simple too me – Crumar Nov 18 '16 at 00:27