![为什么需要这个注释字符才能正确渲染?](https://linux22.com/image/284364/%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81%E8%BF%99%E4%B8%AA%E6%B3%A8%E9%87%8A%E5%AD%97%E7%AC%A6%E6%89%8D%E8%83%BD%E6%AD%A3%E7%A1%AE%E6%B8%B2%E6%9F%93%EF%BC%9F.png)
下面两个子节点之间有一个注释,如果删除它会导致树的渲染完全错误。为什么?
\documentclass[10pt]{article}
\usepackage{tikz}
\usetikzlibrary{trees}
\tikzstyle{every node}=[draw=black, thin, minimum height=3em]
\begin{document}
\footnotesize
\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}
附有评论:
无评论:
答案1
嗯,一般来说,不允许在\node ... ;
或\coordinate ... ;
或\draw ... ;
等里面有空行。原因是空行不仅仅是一个容易修剪的空白,它还会变成\par
,这会在这些地方造成混乱。
因此,代码编译时包含这些空行确实有点令人惊讶。最好避免使用它们:要么完全删除它们,要么至少添加%
,这会“吃掉直到下一个行尾(包括此行尾)的所有内容”,因此不会\par
生成。