在文本宽度中使用 em 单位代替 cm 会移动节点标签

在文本宽度中使用 em 单位代替 cm 会移动节点标签

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

它是漏洞已在 中更正TiKZ 3.00

使用具有测量值的TiKZ 2.10节点产生:text widthcm

在此处输入图片描述

同时em

在此处输入图片描述

使用TikZ 3.0两个代码生成第一个数字。

答案2

根据Ignasi的正确答案,这是2.10中的一个错误。

Till 于 2013 年 12 月底向 CTAN 提交了 v.3.0 并收到回复,由于软件包的复杂性,他们需要时间来验证它。验证仍在进行中:v.3 关于 sourceforge 的讨论

相关内容