为什么需要这个注释字符才能正确渲染?

为什么需要这个注释字符才能正确渲染?

下面两个子节点之间有一个注释,如果删除它会导致树的渲染完全错误。为什么?

\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生成。

相关内容