如何使用 Tikz 绘制垂直层次图?

如何使用 Tikz 绘制垂直层次图?

我正在调查一家公司的收购历史,然后我需要绘制一个层次化的示意图,它不是所谓的流程图,而是像这样: 在此处输入图片描述

然后我在这里尝试了一些 Tikz 代码,我发现这是一个“不可能完成的任务”:

\begin{figure}[H]
%   \centering
\begin{tikzpicture}%[xscale=2,yscale=2]
%    \draw [help lines] (0,0) grid (15,-21);
    \node[draw=none] (a) at (-1,0) {Medtronic};
    \node[draw=none] (b) at (-1,-.5) {\small Ardian Inc};
    \draw[-] (0,0) -- (.5,0);
    \draw[-] (0,-.5) -- (.5,-.5);
    \draw[-] (0.5,0) -- (0.5,-.5);
    \draw[-] (0.5,-.25) -- (1.5,-.25);
    \draw[-] (1.5,-.25) -- (1.5,-1);
    \node[draw=none] at (-.7,-1) {\small Osteotech Inc};
    \draw[-] (0.5,-1) -- (1.5,-1);
    \draw[-] (1.5,-.625) -- (2,-.625);
    \draw[-] (2,-.625) -- (2,-1.5);
    \draw[-] (2,-1.5) -- (1,-1.5);
    \node[draw=none] at (-.1,-1.5) {\small ATS medical};
\end{tikzpicture}

对于这段长代码,我得到了以下内容:

在此处输入图片描述

然后我失去了耐心,不,这不是做这项工作的正确方法,找出每个点/线的坐标是一种愚蠢的方法......

您知道有什么方法/方式/包可以生成这个吗?谢谢!

答案1

好的,那么就不用树了。我复制了你的图表,只是我没有插入文本,所以我一直重复顶部节点的文本。更新:已更正every two node partevery one node part添加\nodepart{one},非常感谢 wcharging!

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{positioning,shapes}
\tikzset{medi/.style={xshift=-5mm,anchor=west,rectangle split,rectangle split parts=2,
rectangle split part align={left,left},%
font=\sffamily},
every two node part/.style={font=\sffamily\small,align=left},
every one node part/.style={font=\sffamily,align=left},
node distance=5mm and 5mm}
\newcommand{\Connect}[3][]{%
\draw[] (X-#2) -- ++(-0.8cm,0) |- (#3.west) coordinate[pos=0.1] (X-#3);}
\begin{document}
\begin{tikzpicture}
\node[medi] (1) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 1,xshift=-3mm] (2) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 2,xshift=-3mm] (3) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 3,xshift=-3mm] (4) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 4,xshift=-3mm] (5) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 5,xshift=-3mm] (6) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 6,xshift=-3mm] (7) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 7,xshift=-3mm] (8) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 8,xshift=-3mm] (9) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 9,xshift=-3mm] (10) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 10,xshift=-3mm] (11) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 11,xshift=-3mm] (12) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\node[medi,below=of 12,xshift=-3mm] (13) {\nodepart{one}Meditronic \nodepart{two} (Founded 1949)};
\draw (1.west) -- ++(-1.2cm,0) |- (2.west) coordinate[pos=0.22] (X-2);
\foreach \Y [evaluate={\X=int(\Y-1)}] in {3,...,13}
{\Connect{\X}{\Y}}
\draw (X-13) -- ++(-0.5cm,0);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容