When em unit is used in text width style directive, resulting label shifts ever so slightly to the left from its center position directed by preceeding text centered.
When using cm unit, label is exactly centered. What am I doing wrong?
MWE with 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 with 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}
Edit:
This is sounding like a bug, as if I add different font sizes to the label as follows: {Teammate6\\\scriptsize Position4\\\scriptsize Location4} then line spacing varies too.


4cmis larger than12em. So, when you specify4cm, the "box" into which the text is placed is lager and hence the boxes are larger and hence things shift. Try changing from4cmto3cmand see the effect. – Peter Grill Feb 12 '14 at 20:1712emis just an arbitrary number, as is4cm. Changing to for instance8emstill keeps label off center, while changing to3cmdoes not. Ultimately, I am not yet aware of any reasonsemunits should behave any different formcm. – ajeh Feb 12 '14 at 20:48emfor setting the width and it's relative to the normal font, but then you use\smallto typeset the entries and it has a different em width. I get perfect centering if I say\smallbefore thetikzpicture(of course the rectangles are smaller). – egreg Feb 12 '14 at 20:49emis width ofMin the current font, thus just another unit of measure, constant within the document. – ajeh Feb 12 '14 at 21:12\smallis somehow an explicit change font (you change the the font size), hence if you really want to have your picture independent from the font changes, replaceemwithcmormm. Somehow it has already been stated in the comments. Please also note that12emis some numberxwith\normalfontsize, then it isx-efor\smallfont size; usingcmdoes not prevent you to compute the box width, even if it would be better to let TikZ compute it for you: it does it normally, hence let it work. – Claudio Fiandrino Feb 13 '14 at 07:23