我对下图有 2 个问题:
- 我只需要减少两个矩阵 N2 和 N5 之间的空间
- 我需要将节点偏移到比它所跨越的矩阵 N2 和 N5 稍大一些
我正在这么做,[fit={([shift={(5em,2em)}]N2-1-1) ([shift={(-5em,-2em)}]N5-4-1)}
但是转变不起作用。
从@Zarko 修改而来的最小工作示例例子如下:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
fit,
matrix,
positioning}
\usepackage{xcolor}
\begin{document}
\tikzset{
arr/.style = {-{Triangle[scale=0.8]},
draw=gray, ultra thick,
shorten >=1mm, shorten <=1mm},
en/.style = {draw=none, fill=none, text=black},
every label/.append style = {name=LN, anchor=south, % <---
font=\bfseries, text=black,
text width=10em, align=flush center, % <---
yshift=1ex}, % <---
FIT/.style = {draw=gray, fill=gray!30, rounded corners,
inner sep=1ex,
fit=#1, node contents={}},
neuron/.style = {matrix of nodes,
nodes={draw=pink, rounded corners, fill=gray!50,
text height=2ex, minimum width=2em,
inner sep=1mm,
text=#1},
row sep=2mm,
outer sep=0mm},
}
\begin{tikzpicture}[
node distance = 0mm and 1mm % <---
]
%%%
\matrix (N2) [neuron=white,
] % <---
{
|[label=Title]| a \\
b \\
d \\
c \\
};
\scoped[on background layer]
\node (f2) [FIT=(N2-1-1) (N2-4-1)];
%%%%
\matrix (N5) [neuron=white, above right=of f2.south east]
{
|[label= Title
]| a \\ % <--- longer label
b \\
d \\
c \\
};
\scoped[on background layer]
\node (f3) [FIT=(N5-1-1) (N5-4-1)];
% <---
\scoped[on background layer]
\node (f4) [fit={([shift={(5em,2em)}]N2-1-1) ([shift={(-5em,-2em)}]N5-4-1)},draw=gray, fill=gray!30,rounded corners, ]{};
\end{tikzpicture}
\end{document}
另外,我尝试通过改变将两个矩阵放在节点 f4 前面,\scoped[on background layer]
这样\scoped[]
有点奏效,但随后文本和矩阵也消失了!
以下是我想要的,但两个特定矩阵之间的空间小于(其他矩阵)
答案1
我想这就是你想要的:
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
backgrounds,
fit,
matrix,
positioning}
\usepackage{xcolor}
\begin{document}
\tikzset{
arr/.style = {-{Triangle[scale=0.8]},
draw=gray, ultra thick,
shorten >=1mm, shorten <=1mm},
en/.style = {draw=none, fill=none, text=black},
every label/.append style = {name=LN, anchor=south, % <---
font=\bfseries, text=black,
text width=10em, align=flush center, % <---
yshift=1ex}, % <---
FIT/.style = {draw=gray, fill=gray!30, rounded corners,
inner sep=1ex,
fit=#1, node contents={}},
neuron/.style = {matrix of nodes,
nodes={draw=pink, rounded corners, fill=gray!50,
text height=2ex, minimum width=2em,
inner sep=1mm,
text=#1},
row sep=2mm,
outer sep=0mm},
}
\begin{tikzpicture}[
node distance = 0mm and 1mm % <---
]
%%%
\matrix (N2) [neuron=white,
] % <---
{
|[label=Title]| a \\
b \\
d \\
c \\
};
%%%%
\matrix (N5) [neuron=white, right=-2.5cm of N2.east]
{
|[label= Title]| a \\ % <--- longer label
b \\
d \\
c \\
};
% <---
\scoped[on background layer]
\node (f4) [FIT={(N2-1-1) (N5-4-1)},draw=gray, fill=gray!30,rounded corners, inner xsep=20pt,inner ysep=1.5ex]{};
\scoped[on background layer]\node (f3) [FIT=(N5-1-1) (N5-4-1)];
\scoped[on background layer]\node (f2) [FIT=(N2-1-1) (N2-4-1)];
\end{tikzpicture}
\end{document}