答案1
改变row sep
和column sep
以及inner sep
和outer sep
改变图像之间的空间(内分隔 + 行/列分隔)以及它们周围框的填充(内分隔 + 外分隔)。
代码
\documentclass{article}
\usepackage{tikz} % loads graphicx
\makeatletter
\newcommand*\repeatMe[2]{%
\ifnum#1=0 \expandafter\@gobble\else\expandafter\@firstofone\fi
{#2\expandafter\repeatMe\expandafter{\the\numexpr#1-1\relax}{#2}}}
\makeatother
\newcommand*\fracobjset{\pgfqkeys{/fracobj}}
\fracobjset{
rows/.initial=4,
cols/.initial=3,
matrix/.style={row sep=.4em, column sep=1.5ex},
node/.style={
name=\tikzmatrixname-\the\pgfmatrixcurrentrow-\the\pgfmatrixcurrentcolumn,
inner sep=+0pt, outer sep=+.125em},
box path/.style={to path={rectangle(\tikztotarget)}},
size/.style args={#1 by #2}{rows={#1}, cols={#2}},
graphics/.initial={height=2em},
box/.style args={#1 to #2}{matrix/.append style={append after command={
(\tikzlastnode-#1.north west) edge[/fracobj/box path]
(\tikzlastnode-#2.south east)}}}}
\newcommand{\fracObj}[2][]{%
\begin{tikzpicture}
\fracobjset{#1}
\pgfkeysgetvalue{/fracobj/graphics}\fracObjGraphicsOptions
\matrix[/fracobj/matrix]{
\repeatMe{\pgfkeysvalueof{/fracobj/rows}}{
\repeatMe{\pgfkeysvalueof{/fracobj/cols}}{
\node[/fracobj/node]{%
\expandafter\includegraphics\expandafter[\fracObjGraphicsOptions]{#2}};
\unless\ifnum\pgfmatrixcurrentcolumn=\pgfkeysvalueof{/fracobj/cols}\relax
\expandafter\pgfmatrixnextcell\fi}
\unless\ifnum\pgfmatrixcurrentrow=\pgfkeysvalueof{/fracobj/rows}\relax
\expandafter\pgfmatrixendrow\fi}
\pgfmatrixendrow};
\end{tikzpicture}}
\begin{document}
\fracObj[box=1-2 to 1-3]{example-image-1x1}
\fracObj[box=1-2 to 1-3,
box=2-1 to 3-2,
box=2-3 to 3-4,
size=3 by 4,
graphics={height=1.5em},
box path/.append style={rounded corners=2pt}
]{example-image-1x1}
\end{document}