我想要实现以下目标:
这是我目前拥有的:
\mystrut
来自这里parbox 的使用来自这里。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}
\begin{document}
\def\mystrut{\vrule height 1.5cm depth 1.5cm width 0pt}
\begin{tikzpicture}[mybox/.style={rectangle split, rectangle split parts=2, draw, text width=3.5cm,text centered}]
\node (AAA) [mybox]
{
\textbf{AAA}
\nodepart{second}\mystrut some description
};
\node (BBB) [right = of AAA,mybox]
{
\textbf{BBB}
\nodepart{second}\mystrut \parbox{3.5cm}{\centering some longer description}
};
\draw[transform canvas={yshift=0.5cm},-stealth](AAA) --(BBB);
\draw[transform canvas={yshift=-0.5cm},-stealth](BBB) --(AAA);
\end{tikzpicture}
\end{document}
我如何嵌套我的盒子?我不必使用rectangle split
节点,它们只是作为搜索中的第一个结果出现。
答案1
你的意思是这样的吗:
该图片(我按照您问题中显示的示例)是通过代码获得的:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning,shapes,arrows}
\begin{document}
\begin{tikzpicture}[
node distance = 0mm,
every node/.style = {draw, text width=3.5cm, inner sep=2mm,
outer sep=0mm, align=center},
headernode/.style = {font=\Large\bfseries},
textnode/.style = {minimum height=30mm},
mybox/.style = {rectangle split, rectangle split parts=2,
font=\scriptsize, text width=13mm, align=center}
]
\node (AA1) [headernode] {AAA};
\node (AA2) [below=of AA1,textnode] {some description};
\node (BB1) [right=16mm of AA1,headernode] {BBB};
\node (BB2) [below=of BB1,textnode] {some longer description};
\node (DD1) [below=16mm of AA2,headernode] {DDD};
\node (DD2) [below=of DD1,textnode] {};
\draw[transform canvas={yshift= 0.5cm},-stealth](AA2) --(BB2);
\draw[transform canvas={yshift=-0.5cm},-stealth](BB2) --(AA2);
% nested boxes
\node (DAA) [above right=2mm of DD2.south west,mybox]
{AAA \nodepart{two} some description};
\node (DBB) [above left=2mm of DD2.south east,mybox]
{BBB \nodepart{two} some description};
\draw[transform canvas={yshift=-0.1cm},-stealth](DAA) --(DBB);
\draw[transform canvas={yshift=-0.4cm},-stealth](DBB) --(DAA);
\end{tikzpicture}
\end{document}
在上面的代码中,我定义了两个节点(在修改后mybox
):“headernode”,它包含(我猜)一个块标题,textnode
它包含 descrriitpin。每个节点都style
定义了所选字体和对齐类型。
对于嵌套节点,我使用mybox
较小的尺寸和字体。