![在文本宽度中使用 em 单位代替 cm 会移动节点标签](https://linux22.com/image/284303/%E5%9C%A8%E6%96%87%E6%9C%AC%E5%AE%BD%E5%BA%A6%E4%B8%AD%E4%BD%BF%E7%94%A8%20em%20%E5%8D%95%E4%BD%8D%E4%BB%A3%E6%9B%BF%20cm%20%E4%BC%9A%E7%A7%BB%E5%8A%A8%E8%8A%82%E7%82%B9%E6%A0%87%E7%AD%BE.png)
当em
在样式指令中使用单位时text width
,结果标签会从其前导指示的中心位置稍微向左移动text centered
。
使用单位时cm
,标签正好居中。我做错了什么?
MWE 具有em
:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black, thin, minimum height=3em, font=\small]
\begin{document}
\begin{tikzpicture}[
supervisor/.style={%
text centered, text width=12em,
text=black
},
teammate/.style={%
text centered, text width=12em,
text=black
},
subordinate/.style={%
grow=down,
xshift=-3.2em, % Horizontal position of the child node
text centered, text width=12em,
edge from parent path={(\tikzparentnode.205) |- (\tikzchildnode.west)}
},
level1/.style ={level distance=4em,anchor=west},
level2/.style ={level distance=8em,anchor=west},
level3/.style ={level distance=12em,anchor=west},
level4/.style ={level distance=16em,anchor=west},
level 1/.style={%
edge from parent fork down,
sibling distance=14em,
level distance=5em
}
]
\node[anchor=south,supervisor](super){Supervisor\\Supervisory position\\Location}[]
child{node [teammate] {Teammate6\\Position4\\Location4}
child[subordinate,level1] {node {Subordinate1}}
child[subordinate,level2] {node {Subordinate2}}}
% - why is this comment required for proper rendering of the tree???
child{node [teammate] {Teammate7\\Position5\\Location5}
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}
\end{document}
MWE 具有cm
:
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black, thin, minimum height=3em, font=\small]
\begin{document}
\begin{tikzpicture}[
supervisor/.style={%
text centered, text width=4cm,
text=black
},
teammate/.style={%
text centered, text width=4cm,
text=black
},
subordinate/.style={%
grow=down,
xshift=-3.2em, % Horizontal position of the child node
text centered, text width=4cm,
edge from parent path={(\tikzparentnode.205) |- (\tikzchildnode.west)}
},
level1/.style ={level distance=4em,anchor=west},
level2/.style ={level distance=8em,anchor=west},
level3/.style ={level distance=12em,anchor=west},
level4/.style ={level distance=16em,anchor=west},
level 1/.style={%
edge from parent fork down,
sibling distance=14em,
level distance=5em
}
]
\node[anchor=south,supervisor](super){Supervisor\\Supervisory position\\Location}[]
child{node [teammate] {Teammate6\\Position4\\Location4}
child[subordinate,level1] {node {Subordinate1}}
child[subordinate,level2] {node {Subordinate2}}}
% - why is this comment required for proper rendering of the tree???
child{node [teammate] {Teammate7\\Position5\\Location5}
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}
\end{document}
编辑:
这听起来像是一个错误,就好像我向标签添加不同的字体大小,如下所示:{Teammate6\\\scriptsize Position4\\\scriptsize Location4}
然后行距也会变化。
答案1
答案2
根据Ignasi的正确答案,这是2.10中的一个错误。
Till 于 2013 年 12 月底向 CTAN 提交了 v.3.0 并收到回复,由于软件包的复杂性,他们需要时间来验证它。验证仍在进行中:v.3 关于 sourceforge 的讨论