I would like to circle the elements in the matrix table (How to create a small cell with borders in the top corner of a cell in the table?) and hatch pattern the matrix table excluding the circled numbers and inlays. I would also like to fill the cells in the demand and supply with red color as indicated in the figure. Please help me.
Please note that the red lines drawn in the figure are approximate, in the final solution, I would like to have perfectly slanted group of lines (45 degree hatch lines).
\documentclass[tikz,border=3mm]{standalone}
\usepackage{amsmath}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}[mmat/.style={matrix of math nodes,nodes in empty cells,
row sep=-\pgflinewidth,column sep=-\pgflinewidth,
nodes={minimum width=5.5em,minimum height=3.5em,
draw,anchor=center,
text depth=0.25ex,text height=0.8em}},
inlay/.style={label={[draw,thin,anchor=north east,minimum width=0.7cm,
minimum height=0em,inner sep=1.4pt]north east:#1}}]
\matrix[mmat] (mat){
& P & Q & R & S & \textit{Supply} \\
A & |[inlay=10]| 300 & |[inlay=20]| 200 & |[inlay=30]| 0 & |[inlay=40]| 0 & 500 \\
B & |[inlay=50]| 0 & |[inlay=60]| & |[inlay=70]| & |[inlay=80]| & 500 \\
C & |[inlay=90]| 0 & |[inlay=100]| & |[inlay=110]| & |[inlay=120]| & 500 \\
Demand & |[inlay=130]| 300 & |[inlay=140]| 200 & |[inlay=150]| 1000 & |[inlay=160]| 500 & 2000 \\
};
\draw (mat-1-1.north west) -- (mat-1-1.south east);
\draw[stealth-] ([yshift=2ex,xshift=-0.5ex]mat-1-1.east)
-- ++ (-2ex,0) node[left,font=\itshape]{To};
\draw[stealth-] ([xshift=3ex,yshift=0.5ex]mat-1-1.south west)
-- ++ (0,2ex) node[above,font=\itshape]{From};
\end{tikzpicture}
\end{document}


pattern={Lines[angle=45,line width=0.7pt]},, which I now changed from-45to45. Is this what you mean? – May 23 '20 at 21:21