下面用 TikZ 绘制的简单图表\graph
我希望红色F节点与其他叶节点出现在同一级别(A,b,C,d)之间是否有任何选项可以跳过某一级别C和F?
相应的代码(用 编译lualatex
):
\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{trees,layered}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\graph [grow down, layered layout] {
A -> {B ->{D, E}, C},
D -> {a, b},
E -> {c, d},
C -> {f[red]}
};
\end{tikzpicture}
\end{frame}
\end{document}
答案1
TikZ 手册已经变得令人难以忍受,有时您必须读第三遍才能最终找到您一直在寻找的选项……
在我的例子中,它们甚至是其中的两个,如第 30 条所述图形绘制算法:分层布局。
变体 1 跳过一层[> minimal layers=2]
:
\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{trees,layered}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\graph [grow down, layered layout] {
A -> {B ->{D, E}, C},
D -> {a, b},
E -> {c, d},
C -> {f[red, > minimum layers=2]}
};
\end{tikzpicture}
\end{frame}
\end{document}
变体 2 使用[same layer]
可以稍后传递给图表的选项:
\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{trees,layered}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\graph [grow down, layered layout] {
A -> {B ->{D, E}, C},
D -> {a, b},
E -> {c, d},
C -> {f[red]};
{[same layer] d, f};
};
\end{tikzpicture}
\end{frame}
\end{document}