You can use the package fletcher – Typst Universe to create such a diagram. The spacing allows you to control the column and row separation, and there are many other settings to modify the formatting.
#import "@preview/fletcher:0.5.8" as fletcher: diagram, node, edge
#let matrix = (
(8, 1, 6),
(3, 5, 7),
(4, 9, 2),
)
#let nodes = matrix.enumerate().map(
((y, row)) => {
row.enumerate().map(((x, v)) => { node((x, y), $#v$) })
}
)
#diagram(
spacing: (1cm, 4pt),
node-stroke: red,
node-shape: rect,
..nodes.flatten(),
node(enclose: ((0, 0), (2, 2)), inset: 4pt)
)
