[Tex/LaTex] How to fix a certain distance between a TikZ matrix border and its nodes

tikz-matrixtikz-pgf

I want to draw a TikZ matrix with its border and I would like to define the distance between most external matrix nodes and matrix border. Something like a matrix inner sep. If I change inner sep in matrix options declaration, all nodes inside the matrix also change its inner separation.

I know how to do it with fit library. I just want to know if its possible without it.

Best Answer

The inner sep for the matrix can be set and then nodes={inner sep=...} can be reset individually for the inner nodes.

\documentclass[tikz]{standalone}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix[draw,matrix of nodes,inner sep=2mm,nodes={draw,inner sep=5mm}](a){
A\\
B\\
C\\
};

\draw[->,thick](a-1-1.base) -| ++(2cm,-5mm) node [right] {5mm};
\draw[->,thick](a.north)    -| ++(2cm,-2mm) node [right] {2mm};
\end{tikzpicture}
\end{document}

enter image description here