我想绘制一个表格,并将一个单元格涂成另一种颜色。由于我对乳胶不太熟悉,我找到了这个例子:
\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}
但是我怎样才能只为一个单元格着色呢?
答案1
您似乎已经知道如何向单个单元格添加选项,|[...]|
因此从这个意义上讲,您几乎已经回答了您自己的问题:添加fill=<color>
这些选项,例如|[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}