我是新手LateX
,我想画一个包含几个节点的复杂图片。我简化了我的问题。我的主要问题是绘制重叠节点。我有以下代码,但我不知道如何制作我想要的重叠。任何帮助都将不胜感激。
\documentclass[border=1pt, tikz]{standalone}
\usetikzlibrary{positioning, fit}
\begin{document}
\begin{tikzpicture}[draw=black, scale=1, transform shape
, every node/.style = {rectangle, draw=black, align=center, inner xsep=6mm, inner ysep=3mm}
]
% change default arrow style
\tikzset{very thick, ->, -latex, shorten <=0pt, shorten >=0pt}
\node[name=outer, minimum width = 4cm, minimum height= 3cm] {};
\node[name=inner, above=(2mm of outer.south)] {Inner Text};
\node[name=inner2, above=(10mm of outer.south)] {Inner Text2};
\end{tikzpicture}
\end{document}
更新:为了更好地描述我的目标,我会说我需要有 4 个矩形(2 个普通矩形,2 个虚线矩形)。其中一个虚线矩形包含上面的普通矩形 + 另一个矩形的 2/3,第二个虚线矩形包含下面普通矩形的剩余 1/3。我应该提到我需要使用node
s,因为所有框(矩形)都必须有标题。此外,颜色是否与图片一样或矩形是否圆角都无关紧要。
另外,标题的确切位置对我来说并不那么重要。我只希望它们清晰(哪个与哪个矩形相关)。因此,它们可以居中或向左调整或任何其他方式。
答案1
你是指这样的吗?
您可以完全使用节点来完成此操作,但我认为绘制外部框的边界并将文本分别放置在没有可见边界的节点中更为直接。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, fit, calc}
\begin{document}
\begin{tikzpicture}
[every node/.style={align=center, inner xsep=6mm, inner ysep=3mm, rounded corners}, very thick]
\node (inner1) [draw] {Inner Text 1};
\node (inner2) [draw, below=of inner1] {Inner Text 2};
\node (outer) [fit=(inner1) (inner2)] {};
\coordinate (o) at ($(inner2.north)!1/3!(inner2.south)$);
\draw [blue, densely dashed, rounded corners] (outer.north west) rectangle (outer.east |- o) node [below=5mm of inner1, anchor=center] {Outer Text 1};
\draw [green, densely dashed, rounded corners] node (outer2) [below=5mm of inner2, anchor=center] {Outer Text 2} (outer.west |- outer2.south) rectangle ([yshift=-\pgflinewidth]outer.east |- o);
\end{tikzpicture}
\end{document}
答案2
像这样?
\documentclass[border=3pt, tikz]{standalone}
\usetikzlibrary{positioning, fit}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm,
every node/.style = {rectangle, draw, rounded corners,
align=center, inner xsep=6mm, inner ysep=3mm}
]
\node (inner1) [minimum width=32mm] {Inner Text};
\node (inner2) [minimum width=32mm, below=of inner1] {Inner Text 2};
%
\node[name=outer1, dashed, draw=blue, fit = (inner1) (inner2.north)] {};
\node[name=outer2, dashed, draw=blue, fit = (inner2.south west) (inner2.south east)] {};
\end{tikzpicture}
\end{document}
附录: 或者这个(正如我指出的那样)车牌)?
(你对此的问题不清楚)
\documentclass[border=3pt, tikz]{standalone}
\usetikzlibrary{positioning, fit}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm,
every node/.style = {rectangle, draw, rounded corners,
align=center, inner xsep=6mm, inner ysep=3mm}
]
\node (inner1) [minimum width=32mm] {Inner Text};
\node (inner2) [minimum width=32mm, below=of inner1] {Inner Text 2};
%
\node[name=outer1, dashed, draw=blue, fit = (inner1) (inner2),
label=center:text of outer node] {};
\end{tikzpicture}
\end{document}
附录(2): 最后一次尝试......根据以下编辑过的问题和评论进行猜测:
\documentclass[border=3mm, tikz]{standalone}
\usetikzlibrary{calc, fit, positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm,
inbox/.style = {rectangle, draw, rounded corners,
minimum height=18mm, minimum width=32mm ,
align=center, inner xsep=6mm, inner ysep=3mm},
outbox/.style = {rectangle, draw=blue, densely dashed, rounded corners,
inner xsep=6mm, inner ysep=1mm}
]
\node (inner1) [inbox,
label={[name=TS] above:Training Set}] {Data 1};
\node (inner2) [inbox, below=of inner1] {Data 2};
\node (test) [above=1mm of inner2.south] {Test Set};
%
\node (outer1) [outbox, fit = (TS) (inner1) ($(inner2.north)!0.25!(inner2.south)$),
label=left:caption 1] {};
\node (outer2) [outbox, fit = ($(inner2.north)!0.75!(inner2.south)$)
(inner2.south west) (inner2.south east),
label=left:caption 2] {};
\end{tikzpicture}
\end{document}