This tutorial shows how to create a checkerboard in LaTeX using the TikZ matrix.

Example: Checkerboard in Latex Using TikZ Matrix

Below example uses [anchor=center][nodes in empty cells]c/.style[row sep=-\pgflinewidth][column sep=-\pgflinewidth];.

\documentclass[12pt, a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\tikzset{c/.style={fill=yellow}}
\tikzset{mystyle/.style={matrix of nodes,
        nodes in empty cells,
        row sep=-\pgflinewidth,
        column sep=-\pgflinewidth,
        nodes={draw,minimum width=1cm,minimum height=1cm,anchor=center}}}

\begin{tikzpicture}
\matrix[mystyle]{
|[c]|&A    &|[c]|&\\
     &|[c]|&B    &|[c]|\\
|[c]|&C    &|[c]|&\\
     &|[c]|&D    &|[c]|\\
};
\end{tikzpicture}
\begin{tikzpicture}
\matrix[mystyle]{
|[c]|&    &|[c]|&\\
&|[c]|&    &|[c]|\\
|[c]|&    &|[c]|&\\
&|[c]|&    &|[c]|\\
};
\end{tikzpicture}
\begin{tikzpicture}
\matrix[mystyle]{
&A    &&\\
&&B    &\\
&C    &&\\
&&D    &\\
};
\end{tikzpicture}
\end{document}  

Output:

Checkerboard chart in LaTeX using TikZ matrix.

See also:

Vinish Kapoor

An Oracle Apex Consultant, Oracle ACE, and founder of foxinfotech.in and orclqa.com a question and answer forum for developers.

Leave a Reply