使用 TikZ,是否可以水平和垂直分割节点?

使用 TikZ,是否可以水平和垂直分割节点?

使用 TikZ,是否可以水平拆分节点垂直?

我目前有的是:

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{shapes}

\begin{document}
\begin{tikzpicture}[every node/.append style={draw, rounded corners, inner sep=10pt}]
    \node [rectangle split, rectangle split horizontal, rectangle split parts=3]
        {Services
         \nodepart{two} Event Driven Framework
         \nodepart{three} OS Adapter Layer};

\end{tikzpicture}
\end{document}

在此处输入图片描述

我想要的是:

/----------+------------------------\
|          | Event Driven Framework |
| Services +------------------------+
|          |    OS Adapter Layer    |
\----------+------------------------/

答案1

据我所知,这在开箱即用时是不可能的。但您可以绘制单独的nodes ,然后绘制线条。甚至更好的是,按照 JLDiaz 的想法,您可以将其作为pic

\documentclass[tikz, border=10pt]{standalone}
\usetikzlibrary{shapes,fit}

\tikzset{
    pics/vhsplit/.style n args = {3}{
        code = {
        \node[text width=2cm] (A) at (0,0) {#1};  
        \node[anchor=south west,text width=2cm] (B) at (A.east) {#2};
        \node[anchor=north west,text width=2cm] (C) at (A.east){#3};
        \node[inner sep=0pt,draw,rounded corners,fit=(A)(B)(C)] {}; 
        \draw (B.north west) -- (C.south west)
              (B.south west) -- (C.north east);    
        }
    }
}


\begin{document}
\begin{tikzpicture}%[every node/.append style={draw, rounded corners, inner sep=10pt}]
    \path pic (a) {vhsplit={Some}{Text}{comes here}};

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我发布此内容是为了记录。我必须解决一个非常相似的问题,该问题允许在三个字段中输入任意长度的文本,尤其是在左侧。此代码中有一些额外内容只是为了展示可能性。

\documentclass{article}

\usepackage{tikz}
\usepackage[papersize={5.5in,8.5in},margin=0.6in,bottom=0.7in]{geometry}
\usepackage{xparse}
\newsavebox{\linetmp}

\usetikzlibrary{fit,shapes.multipart,positioning}

\NewDocumentCommand{\threepart}{mmm}{%
\begin{tikzpicture}
    \node (L) {%
        \sbox{\linetmp}{#1}%
        \ifdim\wd\linetmp<2in%% Fit on one line?
            \bfseries\centering#1
        \else
            \parbox{2in}{\rightskip0pt plus 3em\strut#1\strut}
        \fi
    };
    \node[rounded corners,
        rectangle split,
        rectangle split parts=2,
        text width=2in,
        align=center,
        right= 0pt of L.east] (R) {%
            \bfseries\strut#2\strut
            \nodepart{two}\itshape\strut#3\strut};
    \draw[thick]  (R.text split east) -- (R.text split west);
    \node[inner sep=0pt,
        draw,
        thick,
        rounded corners,
        fit=(L)(R)] (W) {};
    \draw[thick] (W.south west -| R.west) -- (W.north west -| R.west);
\end{tikzpicture}%
}

\begin{document}

\noindent
\threepart{Services}{Event Driven Framework}{OS Adapter Layer}

\bigskip

\noindent
\threepart{Some very long text in the left field}{Some very long text in the upper right field}{Some very long text in the lower right field}

\end{document}

三部分“节点”示例

相关内容