在尝试使用问题的答案中的代码后出现了以下问题TikZ-tree:水平组织结构图中的边缘对齐
问题 1:如您所见,我将纸张格式更改为使用 B(11x17),图片也相应缩放,包括框内的文本。由于需要较小的文本大小,我尝试将 12pt 更改为 10pt。它没有改变文本大小,而是改变了框的宽度。代码中需要什么才能使用较小的文本而不改变树布局?
问题 2:为什么换\\
行在队友和下属样式中有效,但在主管节点中无效?它需要自己的样式吗?
问题 3:是否可以保持单位统一,即不使用单位,pt, cm, ex, em
但将单位的使用限制在所需的最低限度?
问题 4:我在 CTAN 上找不到 Tikz 包和树库。我在哪里可以找到文档?
\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[landscape,paper=ansibpaper]{geometry}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black,thick,anchor=west, minimum height=2.5em]
\begin{document}
\begin{figure}[!htb]
\resizebox{\linewidth}{!}{
\begin{tikzpicture}[
teammate/.style={text centered, text width=3cm, fill=gray!10},
subordinate/.style={%
grow=down, xshift=0em,
text centered, text width=3cm,
edge from parent path={(\tikzparentnode.225) |- (\tikzchildnode.west)}},
level1/.style ={level distance=8ex},
level2/.style ={level distance=16ex},
level3/.style ={level distance=24ex},
level4/.style ={level distance=32ex},
level5/.style ={level distance=40ex},
level 1/.style={sibling distance=10em}]
% Supervisor
\node[anchor=south]{Supervisor \\ Supervisory position}
[edge from parent fork down]
% Teammate and Subordinates
child{node [teammate] {Teammate1}
child[subordinate,level1] {node {Subordinate\\Position1\\Location1}}
child[subordinate,level2] {node {Subordinate2}}
child[subordinate,level3] {node {Subordinate3}}
child[subordinate,level4] {node {Subordinate4\\Position4\\Location4}}
child[subordinate,level5] {node {Subordinate5\\Position5\\Location5}}}
%
child{node [teammate] {Teammate2}
child[subordinate,level1] {node {Subordinate1}}
child[subordinate,level2] {node {Subordinate2}}
child[subordinate,level3] {node {Third\\Teammate}}
child[subordinate,level4] {node {Longtext-\\teammate}}}
%
child{node [teammate] {Teammate3}
child[subordinate,level1] {node {Subordinate\\two lines}}
child[subordinate,level2] {node {Subordinate2}}
child[subordinate,level3] {node {Subordinate3}}}
%
child{node [teammate] {Teammate4}
child[subordinate,level1] {node {Subordinate1}}
child[subordinate,level2] {node {Subordinate2}}}
%
child{node [teammate] {Teammate5}
child[subordinate,level1] {node {First\\Subordinate}}
child[subordinate,level2] {node {Subordinate2}}
child[subordinate,level3] {node {Third\\Teammate}}
child[subordinate,level4] {node {Longtext-\\teammate}}};
\end{tikzpicture}}
\caption{This is an org chart}
\end{figure}
\end{document}
答案1
主管节点缺少宽度和对齐样式。其他节点已经具有text centered, text width=3cm
样式,允许换行。
建议:从基本风格开始,并继承此风格,在需要时添加或更改设置。
\begin{tikzpicture}[
position/.style = {text centered, text width=3cm},
supervisor/.style = {position, text width=4cm, anchor=south},
teammate/.style = {position, fill=gray!10},
subordinate/.style = {position,
grow=down, xshift=0em,
...
这是 Q1,关于 Q1 和 Q3:尽可能多地使用样式,Q4:CTAN 上的 PGF或者SourceForge。(提示:该包的实际名称是 PGF,TikZ 只是前端部分)。