# How can I draw a chessboard missing two diagonally opposite corner squares?

How can I draw of a mutilated chessboard, i.e. missing two diagonally opposed corner squares? Using the chessboard package, I can only draw a full chessboard...

-
Can you please add a MWE? Refer: minimal working example (MWE) –  Harish Kumar Mar 28 '14 at 11:32

A PSTricks solution:

\documentclass{article}

\usepackage{multido}
\usepackage{pstricks}

\def\boardsize{8 } % a space after the number is required

\begin{document}

\begin{pspicture}(\boardsize,\boardsize)
\psset{dimen = middel}
\multido{\iA = 0+1}{\numexpr\boardsize-1}{%
\multido{\iC = 1+1}{\numexpr\boardsize-1}{\psframe(!\iC\space \boardsize 1 sub)(!\iC\space 1 add \boardsize)}
\multido{\iD = 1+1}{\numexpr\boardsize-2}{\psframe(!\boardsize 1 sub \iD)(!\boardsize \iD\space 1 add)}
\end{pspicture}

\end{document}


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

Update

In case you want to draw lines instead of squares, you can use the following:

\documentclass{article}

\usepackage{multido}
\usepackage{pstricks}

\def\boardsize{8 } % a space after the number is required

\begin{document}

\begin{pspicture}(\boardsize,\boardsize)
\psset{linecap = 2}
\multido{\iA = 1+1}{\numexpr\boardsize-1}{\psline(\iA,0)(\iA,\boardsize)}
\multido{\iB = 1+1}{\numexpr\boardsize-1}{\psline(0,\iB)(\boardsize,\iB)}
\psline(0,0)(!0 \boardsize 1 sub)
\psline(\boardsize,1)(\boardsize,\boardsize)
\psline(0,0)(!\boardsize 1 sub 0)
\psline(1,\boardsize)(\boardsize,\boardsize)
\end{pspicture}

\end{document}

-
\multido{\iA=0+1}{\numexpr\rows-1}{% doesn't need additional packages –  Herbert Mar 28 '14 at 11:59
I'm not familiar with the PStricks syntax. What does this do? Does it draw lines or squares? –  Jubobs Apr 2 '14 at 14:08
@Jubobs \psframe draws a rectangle. (I've set the height equal to the width so squares are drawn.) \multido{...}{...}{\multido{...}{...}{...}} draws the first n-1 rows and n-1 columns. The last two \multido macros draw the upper row and right-most column, respectively. –  Svend Tveskæg Apr 2 '14 at 14:12
Why the downvote? If I need to change something, please let me know. –  Svend Tveskæg Aug 23 '14 at 5:15
I did not down vote PSTricks related answers and questions. Instead, I always up vote them. –  kiss my armpit Aug 23 '14 at 12:19

This is easily done with \foreach; see section 56 of the TikZ/PGF manual.

### Remark on efficiency

Drawing the squares of the chessboard (as in Svend Tveskæg's first approach and <guy-whose-name-always-changes>'s answer) is rather inefficient; the corresponding algorithmic complexity is Θ(n^2), where n is the number of rows. Drawing the lines of the chessboard, in comparison, requires less work; the corresponding complexity is merely Θ(n). Therefore, it's better to draw the chessboard's lines rather than the squares.

This sort of consideration may not matter much for a one-off, small chessboard, but if you want to draw this type of diagram multiple times in your document, and/or if you want to draw chessboards with an unusually large number of squares (n-by-n with large n), you may want to draw lines instead of squares to reduce compilation time.

\documentclass{article}

\usepackage{tikz}
\tikzset{chessboard/.style={thick}}%

\begin{document}
\begin{tikzpicture}
\newif\iffirstdiag          % Switch to control which corners are ommitted.
\firstdiagtrue              % (flip the switch here)
%
\pgfmathtruncatemacro\N{8}  % number of rows/columns
\pgfmathtruncatemacro\Nmone{\N-1}
%
% draw internal lines
\foreach \i in {1,2,...,\Nmone}
{
\draw[chessboard] (0,\i) -- (\N,\i);  % We control the horizontals...
\draw[chessboard] (\i,0) -- (\i,\N);  % ...and the verticals.
% We can deluge you with a thousand
% channels or expand one single
% image to crystal clarity and
% beyond...
}
%
% draw external lines
\iffirstdiag
\draw[chessboard] (0,0)  -- (\Nmone,0);    % bottom
\draw[chessboard] (1,\N) -- (\N,\N);       % top
\draw[chessboard] (0,0)  -- (0,\Nmone);    % left
\draw[chessboard] (\N,1) -- (\N,\N);       % right
\else
\draw[chessboard] (1,0)  -- (\N,0);        % bottom
\draw[chessboard] (0,\N) -- (\Nmone,\N);   % top
\draw[chessboard] (0,1)  -- (0,\N);        % left
\draw[chessboard] (\N,0)  -- (\N,\Nmone);  % right
\fi
\end{tikzpicture}
\end{document}

-

Another solution with PSTricks. Just for the sake of reducing the number of keystrokes used in the other existing answers.

Features:

1. You can change the number of cells just by changing the number 4 to any positive integer.
2. The code uses minimal number of keystrokes to save more bytes. Go green!
3. The used algorithm is easy to understand but it does not hurt you for a "relatively small" number of \N.

## PSTricks solution (recommended)

\documentclass[pstricks,border=12pt]{standalone}

\def\N{5}
\def\M{\numexpr\N-1}
\def\A{\multips(0,1){\M}{\multips(1,0){\M}{\psframe(1,1)}}}

\begin{document}

\begin{pspicture}[dimen=m](\N,\N)
\A\rput(1,1){\A}
\end{pspicture}

\end{document}


## TikZ solution

\documentclass[tikz,border=12pt]{standalone}

\def\N{5}
\def\M{\numexpr\N-1}
\def\A{\tikz{\foreach \j in {1,...,\M}{\foreach \i in {1,...,\M}{\draw (\i,\j) rectangle +(1,1);}}}}

\begin{document}
\tikz \draw (0,0) node {\A} (1,1) node {\A};
\end{document}

-
O(M^2) complexity! You're saving keystrokes but you're also wasting CPU cycles :p –  Jubobs Mar 29 '14 at 20:44

A simple tabular:

\documentclass{article}
\usepackage{array}
\begin{document}

{\tabcolsep=0pt
\begin{tabular}{|*{8}{>{\rule{0pt}{1cm}\rule{1cm}{0pt}}c|}}\cline{2-8}
\multicolumn{1}{c|}{}&&&&&&& \\\hline
&&&&&&& \\\hline
&&&&&&& \\\hline
&&&&&&& \\\hline
&&&&&&& \\\hline
&&&&&&& \\\hline
&&&&&&&\multicolumn{1}{c}{} \\\cline{1-7}
\end{tabular}}
\end{document}


-
If the chessboard is allowed to have more or fewer rows than 8, your approach is not very maintainable. –  Jubobs Mar 28 '14 at 11:58