How to draw a chessboard filled with numbers, as the following figure?


I've tried using the chessboard package but to no success.

  • 5
    What have you tried so far? A minimal working example (MWE) will help us help you. :-) Mar 28 '14 at 18:28
  • 4
    Please review the answers to your other questions and accept them when applicable... Regarding this question, you have to show us what you've tried so far. Post a minimal working example (MWE).
    – jub0bs
    Mar 28 '14 at 18:30
  • 1
    See the PGF-TikZ Manual (for version 3.0) sec. 2.20 pag. 42.
    – Pier Paolo
    Mar 28 '14 at 18:44
  • It is unclear how do I the external numbering of rows and columns
    – benedito
    Mar 28 '14 at 19:15
  • 5
    This is not a chessboard: There are no dark fields, the columns are numbered instead of using a-h. There are no chess pieces. It's an 8x8 tabular with row and column numbers. The chessboard package is the wrong tool. Mar 28 '14 at 21:02

If you really want to use a chessboard...

chess board




\row{8} \row{7} \row{6} \row{5} \row{4} \row{3} \row{2} \row{1}}&\board{#1}\\
\row{ } &\mbox{\col{a}\col{b}\col{c}\col{d}\col{e}\col{f}\col{g}\col{h}}

\raisebox{.35\symsize}{\makebox[\symsize][c]{\small #1}}}
\raisebox{.35\symsize}{\makebox[\symsize][c]{\small #1}}}




Overlaying the text on top of \WhiteEmptySquare is sort of wasteful but the chessfss package sometimes uses two different colors, not just black and white.

  • Why didn't you use looping approach to save more keystrokes? Apr 6 '14 at 8:30
  • 2
    For a one-off, I'd rather type than debug. Apr 6 '14 at 14:31

\foreach \x in {1,2,...,8}
\foreach \y in {1,2,...,8}
\draw (\x,\y) +(-.5,-.5) rectangle ++(.5,.5);
\draw (\x,\y) node{\small (\y,\x)};
\foreach \x in {1,2,...,8}{
\node at (\x,0) {\x};
\node at (0,\x) {\x};

enter image description here


A MetaPost solution, drawing something like a real chessboard, for the fun:

input latexmp; setupLaTeXMP(textextlabel = enable, mode = rerun);
u := 1.5cm; 
n := 8;
picture mypoint;
  for i = 1 upto n:
    for j = 1 upto n:
      mypoint := thelabel("$(" & decimal j & "," & decimal i & ")$", u*(i-.5, j-.5));
      if (i+j) mod 2 = 0:
        fill ((i-1, j-1) -- (i, j-1) -- (i, j) -- (i-1, j) -- cycle) scaled u;
        draw mypoint withcolor white;
      else: draw mypoint;
    label.bot("$" & decimal i & "$", u*(i-.5, 0));
    label.lft("$" & decimal i & "$", u*(0, i-.5));
  draw (origin -- (n, 0) -- (n, n) -- (0, n) -- cycle) scaled u;
  setbounds currentpicture to boundingbox currentpicture enlarged 2bp;

If interested, typeset it with the Metafun format. For example, to obtain a PDF version directly, you can enter this in a command line:

mptopdf -metafun -latex chessboard.mp

The result is:

enter image description here


Just another much better solution with PSTricks.

    {% <--- I really don't understand why we need to append % here right before \pstVerb.
        \pstVerb{/hx \ix\space .5 sub def}
        \uput[d](!hx 0){$\char\ic\mathstrut$}
        \uput[l](!0 hx){$\ix\mathstrut$}
            \psframe[origin={\ix,\iy},fillstyle=\ifodd\io solid\else vlines\fi,hatchsep=.5pt,hatchcolor=lightgray](-1,-1)
            \rput(!hx \iy\space .5 sub){$(\iy,\ix)$}

enter image description here

  • I can't compile it. Appears the errors: Line 15 - Missing number, treated as zero and Line 15 -Illegal unit measure (pt inserted)
    – benedito
    Jul 10 '14 at 8:15
  • @benedito: Compile it with latex-dvips-ps2pdf sequence or xelatex. Jul 10 '14 at 10:35
  • I tried - To see the message that appears : Miktex Problem Report:Windows API error 2 The system cannot find the file specified.(before I saved archive)
    – benedito
    Jul 10 '14 at 11:29

A PSTricks solution using the xfp package:


\psset{dimen = m}

% Constants. 

% Parameters.


  \multido{\iB = 1+1}{\boardsize}{%
    \multido{\iA = 1+1}{\boardsize}{%



All you have to do is choose the value of \squaresize and \boardsize.

  • Svend, You code does not compile. I get an error on the last line. Hakarl
    – Hakarl
    Jun 25 '18 at 12:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.