# How can I color one cell of a table using a tikzpicture?

I want to draw a table, and color one cell in another color. As I'm not that experienced in latex, I found this example:

\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{amsthm}
\usepackage{colortbl}

\begin{table}[h]
\label{table prisoners dilemma with Nash}
\centering
\begin{tikzpicture}[element/.style={minimum width=1.75cm,minimum height=0.85cm}]
\matrix (m) [matrix of nodes,nodes={element},column sep=-\pgflinewidth, row sep=-\pgflinewidth,]{
& Deny  & Confess  \\
Deny & |[draw]|-1,-1 & |[draw]|-4,0 \\
Confess & |[draw]|0,-4 & |[draw]| -3,-3 \\
};

\node[above=0.25cm] at ($(m-1-2)!0.5!(m-1-3)$){\textbf{Prisoner 2}};
\node[rotate=90] at ($(m-2-1)!0.5!(m-3-1)+(-1.25,0)$){\textbf{Prisoner 1}};
\end{tikzpicture}
\caption{Normal Form Representation of the Prisoner's Dilemma: the Nash Equilibrium is marked red}
\end{table}


But how can I color only one cell?

• The simple solution is: \definecolor{myColor}{RGB}{230,185,184} \cellcolor{myColor}Content – Michael S. May 20 '16 at 11:08

You seem to know how to add options to individual cells, with |[...]| already, so in that sense you've almost answered your own question: Add fill=<color> in those options, e.g. |[fill=blue!20]|.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,matrix}
\usepackage{amsthm}
\usepackage{colortbl}
\begin{document}
\begin{table}[h]
\label{table prisoners dilemma with Nash}
\centering
\begin{tikzpicture}[element/.style={minimum width=1.75cm,minimum height=0.85cm}]
\matrix (m) [matrix of nodes,nodes={element},column sep=-\pgflinewidth, row sep=-\pgflinewidth]{
& Deny  & Confess  \\
Deny & |[draw]|$-1,-1$ & |[draw,fill=red!20]|$-4,0$ \\
Confess & |[draw]|$0,-4$ & |[draw]| $-3,-3$ \\
};

\node[above=0.25cm] at ($(m-1-2)!0.5!(m-1-3)$){\textbf{Prisoner 2}};
\node[rotate=90] at ($(m-2-1)!0.5!(m-3-1)+(-1.25,0)$){\textbf{Prisoner 1}};
\end{tikzpicture}
\caption{Normal Form Representation of the Prisoner's Dilemma: the Nash Equilibrium is marked red}
\end{table}
\end{document}


• Thank you, it solved my problem. I was overthinking that problem :D – Jonas May 20 '16 at 13:20