编辑

编辑

我在 TikZ 中保存了一个大型组织结构图,我喜欢能够完整地呈现它,但是当只想查看单个团队(树的分支)时,处理起来很麻烦。有人知道我如何定义树的每个分支,单独呈现分支,以及将它们呈现为彼此相关,但只需更新各个分支,并让概览/聚合树引用各个分支吗?

所以这就是我现在得到的,当然,真实的东西在渲染时要大得多,也更笨重:

% WHAT I HAVE NOW (OVERVIEW, GIANT TABLE)
\documentclass{article}
\usepackage{xltxtra}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{verbatim}
\usepackage[active, tightpage]{preview}
\usepackage{graphicx}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{trees,calc,angles,positioning,intersections}
\tikzset{font=\small, level distance=7cm}
\tikzset{grow=right}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west,minimum height=8mm,rectangle,rounded corners,draw=black,thin,align=left,text depth=0pt}}
\tikzset{edge from parent/.style={draw,edge from parent path={(\tikzparentnode.east)-- +(0,0pt)-| (\tikzchildnode.west)}}}
\tikzset{sibling distance=1cm}
\begin{document}
\begin{tikzpicture}
\Tree [.{Leader 1}
        [.{Manager 1}
                [.{Individual Contributor 1} ]
                [.{Individual Contributor 2} ]
                [.{Individual Contributor 3} ]
                [.{Individual Contributor 4} ]
                [.{Individual Contributor 5} ]
                [.{Individual Contributor 6} ]
        ]
        [.{Manager 2}
                [.{Individual Contributor 7} ]
                [.{Individual Contributor 8} ]
                [.{Individual Contributor 9} ]
                [.{Individual Contributor 10} ]
                [.{Individual Contributor 11} ]
                [.{Individual Contributor 12} ]
        ]
        [.{Manager 3}
                [.{Individual Contributor 13} ]
                [.{Individual Contributor 14} ]
                [.{Individual Contributor 15} ]
                [.{Individual Contributor 16} ]
                [.{Individual Contributor 17} ]
                [.{Individual Contributor 18} ]
        ]
    ]
\end{tikzpicture}
\end{document}

这就是我想要做的事情:

% WHAT I WOULD LIKE TO HAVE
\documentclass{article}
\usepackage{xltxtra}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{tikz-qtree}
\usepackage{verbatim}
\usepackage[active, tightpage]{preview}
\usepackage{graphicx}
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
\PreviewEnvironment{tikzpicture}
\usetikzlibrary{trees,calc,angles,positioning,intersections}
\tikzset{font=\small, level distance=7cm}
\tikzset{grow=right}
\tikzset{execute at begin node=\strut}
\tikzset{every tree node/.style={anchor=base west,minimum height=8mm,rectangle,rounded corners,draw=black,thin,align=left,text depth=0pt}}
\tikzset{edge from parent/.style={draw,edge from parent path={(\tikzparentnode.east)-- +(0,0pt)-| (\tikzchildnode.west)}}}
\tikzset{sibling distance=1cm}
\begin{document}

\begin{tikzpicture} % TEAM ONE (SUBTREE TWO)
        \Tree [.{Manager 1}
                [.{Individual Contributor 1} ]
                [.{Individual Contributor 2} ]
                [.{Individual Contributor 3} ]
                [.{Individual Contributor 4} ]
                [.{Individual Contributor 5} ]
                [.{Individual Contributor 6} ]
        ]
\end{tikzpicture}

\begin{tikzpicture} % TEAM TWO (SUBTREE TWO)
        \Tree [.{Manager 2}
                [.{Individual Contributor 7} ]
                [.{Individual Contributor 8} ]
                [.{Individual Contributor 9} ]
                [.{Individual Contributor 10} ]
                [.{Individual Contributor 11} ]
                [.{Individual Contributor 12} ]
        ]
\end{tikzpicture}

\begin{tikzpicture} % TEAM THREE (SUBTREE THREE)
        \Tree [.{Manager 3}
                [.{Individual Contributor 13} ]
                [.{Individual Contributor 14} ]
                [.{Individual Contributor 15} ]
                [.{Individual Contributor 16} ]
                [.{Individual Contributor 17} ]
                [.{Individual Contributor 18} ]
        ]
\end{tikzpicture}

\begin{tikzpicture} % THE OVERVIEW TREE, WITH EVERYTHING
\Tree [.{Leader 1}
        % SUBTREE ONE / OF MANAGER 1
        % SUBTREE TWO / OF MANAGER 2
        % SUBTREE THREE / OF MANAGER 3
    ]
\end{tikzpicture}

\end{document}

答案1

您可以保存树以保存框,然后在最终树的节点中重复使用它们。或者您可以使用森林。以下解决方案包括一个不那么可怕的黑客,图片由 Sašo Živanović 提供解决重用组合树中的树时出现的错误。

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{forest}
\begin{document}
\forestset{
  default preamble={
    for tree={
      align=center,
      child anchor=parent,
      draw,
    },
  },
  merge/.style={% less horrible hack from Sašo Živanović: https://tex.stackexchange.com/questions/382769/how-can-i-get-correct-spacing-when-reusing-forest-trees-and-when-calign-is-cente?noredirect=1#comment947335_382769
    replace by=#1,
    for group={name=#1, first}{s=0}
  }
}

\Forest*{
  [Manager 1, name=m1
    [Individual\\Contributor 1]
    [Individual\\Contributor 2]
    [Individual\\Contributor 3]
    [Individual\\Contributor 4]
    [Individual\\Contributor 5]
    [Individual\\Contributor 6]
  ]
}

\Forest*{
  [Manager 2, name=m2
    [Individual\\Contributor 7]
    [Individual\\Contributor 8]
    [Individual\\Contributor 9]
    [Individual\\Contributor 10]
    [Individual\\Contributor 11]
    [Individual\\Contributor 12]
  ]
}

\Forest*{
  [Manager 3, name=m3
    [Individual\\Contributor 13]
    [Individual\\Contributor 14]
    [Individual\\Contributor 15]
    [Individual\\Contributor 16]
    [Individual\\Contributor 17]
    [Individual\\Contributor 18]
  ]
}

\Forest*{
  [Leader 1
    [, merge=m1]
    [, merge=m2]
    [, merge=m3]
  ]
}

\end{document}

森林组合

编辑

这是一个修改后的版本,它模拟了问题当前版本中应用于树的样式。

风格版本

\documentclass[border=10pt,multi,tikz]{standalone}
\usepackage{forest}
\begin{document}
\forestset{
  default preamble={
    for tree={
      align=center,
      child anchor=parent,
      draw,
      grow'=0,
      rounded corners,
      parent anchor=children,
      anchor=parent,
      edge path'={(!u.parent anchor) -| (.child anchor)},
    },
  },
  merge/.style={% less horrible hack from Sašo Živanović: https://tex.stackexchange.com/questions/382769/how-can-i-get-correct-spacing-when-reusing-forest-trees-and-when-calign-is-cente?noredirect=1#comment947335_382769
    replace by=#1,
    for nodewalk={fake={name=#1}, last, fake=parent, first}{s'=0pt},
  }
}

\Forest*{
  [Manager 1, name=m1
    [Individual Contributor 1]
    [Individual Contributor 2]
    [Individual Contributor 3]
    [Individual Contributor 4]
    [Individual Contributor 5]
    [Individual Contributor 6]
  ]
}

\Forest*{
  [Manager 2, name=m2
    [Individual Contributor 7]
    [Individual Contributor 8]
    [Individual Contributor 9]
    [Individual Contributor 10]
    [Individual Contributor 11]
    [Individual Contributor 12]
  ]
}

\Forest*{
  [Manager 3, name=m3
    [Individual Contributor 13]
    [Individual Contributor 14]
    [Individual Contributor 15]
    [Individual Contributor 16]
    [Individual Contributor 17]
    [Individual Contributor 18]
  ]
}

\Forest*{
  [Leader 1
    [, merge=m1]
    [, merge=m2]
    [, merge=m3]
  ]
}
\end{document}

相关内容