树的节点/子节点布局允许将节点文本分成多行。我尝试对图表进行同样的操作,但 luaLatex 编译从未完成(使用 Texmaker),我不得不停止它,这会产生如下错误Undefined control sequence \\
是否也可以用图形来打破节点文本?
\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}
\begin{document}
\begin{tikzpicture}
\graph [
binary tree layout,
sibling distance=4mm,
level distance=8mm,
components go right top aligned,
component sep=1pt,
nodes=draw
]
{
Supervisor
-- Current Employee %\\ Current Employee Position
-- {
Subordinate 1--{Worker 01,Worker 02},
Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
},
Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
};
};
\end{tikzpicture}
\end{document}
上述 MWE 有效,但如果我删除评论,它就不会......
此 MWE 的目的是避免对我正在处理的组织结构图进行大量节点大小和位置计算。
编辑:
只是为了澄清一下,图形布局中的节点文本似乎直接用作节点名称,用于将节点链接在一起、对齐层/级别等,因此新行甚至逗号都会破坏编译。
目前,图形布局似乎处于测试阶段,仅适用于非常简单的一两个单词节点,没有涉及换行符或逗号的标点符号 :(
我会尝试在 Sourceforge 上让 Till 注意这一点,看看会有什么结果。
答案1
使用
"Current Employee \\ Current Employee Position"[align=center]
或者
CE[as={Current Employee \\ Current Employee Position},align=center]
或者
CE/"Current Employee \\ Current Employee Position"[align=center]
其中CE
是节点名称。
代码:
\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}
\begin{document}
\begin{tikzpicture}
\graph [
binary tree layout,
sibling distance=4mm,
level distance=8mm,
components go right top aligned,
component sep=1pt,
nodes=draw
]
{
Supervisor
-- CE[as={Current Employee \\ Current Employee Position},align=center]
-- {
Subordinate 1--{Worker 01,Worker 02},
Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
},
Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
};
};
\end{tikzpicture}
\end{document}
您还可以将图像与此节点文本并排插入:
\documentclass[10pt,landscape,letterpaper]{article}
\usepackage{tikz}
\usetikzlibrary{graphs, graphdrawing}
\usegdlibrary{trees, layered}
\usepackage{varwidth}
\usepackage{mwe}% example image
\begin{document}
\begin{tikzpicture}
\graph [
binary tree layout,
sibling distance=4mm,
level distance=8mm,
components go right top aligned,
component sep=1pt,
nodes=draw
]
{
Supervisor
-- CE[as={%
\begin{varwidth}[b]{.5\linewidth}
\centering Current Employee \\ Current Employee Position
\end{varwidth}
\includegraphics[height=1.5\baselineskip]{example-image}}
]
-- {
Subordinate 1--{Worker 01,Worker 02},
Subordinate 2--{SubSubordinate 21--{Worker 21,Worker 22,Worker 23}
},
Subordinate 3-- SubSubordinate01--{Worker 11,Worker 12}
};
};
\end{tikzpicture}
\end{document}