This is related to Baseline of tikz picture within brackets but is a separate issue.
Consider the following MWE:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix} % for "matrix of math nodes"
\begin{document}
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\matrix[matrix of math nodes, draw, nodes={draw}] {
a & b & c \
d & e & f \
};
\end{tikzpicture}
\end{equation}
\end{document}
It produces this output:
I would like to get rid of the space between the nodes inside the matrix and the bounding box of the matrix. Setting the matrix's inner sep to 0 achieves this --- but it also changes the inner sep of all the nodes inside the matrix, which isn't what I want:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix} % for "matrix of math nodes"
\begin{document}
\begin{equation}
\begin{tikzpicture}[baseline=(current bounding box.center)]
\matrix[matrix of math nodes, draw, nodes={draw}, inner sep=0pt] {
a & b & c \
d & e & f \
};
\end{tikzpicture}
\end{equation}
\end{document}
How can I change the inner sep of the matrix node while leaving the nodes inside it alone?
I found a near-duplicate question, How to fix a certain distance between a TikZ matrix border and its nodes? . However, the answer to that question just sets the inner sep of the nodes explicitly, which I want to avoid - I want to just leave each node's inner sep at whatever value it would have if it wasn't in the matrix.





nodes={draw}tonodes={draw, inner sep=10pt}. – M. Al Jumaily Aug 10 '22 at 07:22