我正在用该包制作一些不那么简单的流程图graphdrawing
,并且我想在每个节点周围画一个框。
这可能吗,同时保留简单的语法?如果可以,怎么做?
平均能量损失
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\end{tikzpicture}
\end{document}
答案1
更换线路
\begin{tikzpicture}
经过
\begin{tikzpicture}[every node/.style={draw}]
通过运行获得lualatex
:
\RequirePackage{luatex85}
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[every node/.style={draw}] % <<<<<<<<
\graph[tree layout, grow=down]
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\end{tikzpicture}
\end{document}
答案2
设置图形中节点样式的标准方法是使用nodes
图形的键。
例如,要绘制此图中所有节点的边框,请添加nodes=draw
:
\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{graphdrawing,graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph[tree layout, grow=down, nodes=draw] % somehow make each node have a box around it by putting an option here?
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\end{tikzpicture}
\end{document}
根据您使用every node
或graphs/nodes
,受影响的节点将更多或更少。此外,将选项传递给\graph
或tikzpicture
也会影响结果。
以下是三种可能性:
- 添加
nodes=draw
到\graph
->此图中受影响的节点。 - 添加
graphs/nodes=draw
到tikzpicture
->所有受影响的图中的节点。 - 添加
every node/.append style=draw
到tikzpicture
->此图片中所有受影响的常规节点(但不包括标签等)。
区别如下:
代码:
\IfFileExists{luatex85.sty}{\RequirePackage{luatex85}}{}
\documentclass[border=10pt,multi,tikz]{standalone}
\usetikzlibrary{graphdrawing,graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}
\graph[tree layout, grow=down, nodes=draw] % somehow make each node have a box around it by putting an option here?
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\begin{scope}[yshift=-50mm]
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Fly a kite -> Enjoy the sunshine -> Learn Mandarin,
Fly a kite -> Hate the rain -> Hibernate,
Learn Mandarin -> Impress the Empress.,
Learn Mandarin -> Insult the Emperor -> Abandoned in jail.,
Hibernate -> Horrendous nightmares.,
Hibernate <-> Sweet dreams,
};
\end{scope}
\node [font=\ttfamily, anchor=north, label=below:{as option to \ttfamily\textbackslash graph}] at ([yshift=-5mm]current bounding box.south) {nodes};
\end{tikzpicture}
\begin{tikzpicture}[graphs/nodes=draw]
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\begin{scope}[yshift=-50mm]
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Fly a kite -> Enjoy the sunshine -> Learn Mandarin,
Fly a kite -> Hate the rain -> Hibernate,
Learn Mandarin -> Impress the Empress.,
Learn Mandarin -> Insult the Emperor -> Abandoned in jail.,
Hibernate -> Horrendous nightmares.,
Hibernate <-> Sweet dreams,
};
\end{scope}
\node [font=\ttfamily, anchor=north, label=below:as global option] at ([yshift=-5mm]current bounding box.south) {graphs/nodes};
\end{tikzpicture}
\begin{tikzpicture}[every node/.append style=draw]
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Enter the tavern -> Like each other -> Go adventuring,
Enter the tavern -> Hate each other -> Fight,
Go adventuring -> Utter defeat.,
Go adventuring -> Find treasure -> Utter defeat.,
Fight -> Utter defeat.,
Find treasure <-> Sell treasure,
};
\begin{scope}[yshift=-50mm]
\graph[tree layout, grow=down] % somehow make each node have a box around it by putting an option here?
{
Fly a kite -> Enjoy the sunshine -> Learn Mandarin,
Fly a kite -> Hate the rain -> Hibernate,
Learn Mandarin -> Impress the Empress.,
Learn Mandarin -> Insult the Emperor -> Abandoned in jail.,
Hibernate -> Horrendous nightmares.,
Hibernate <-> Sweet dreams,
};
\end{scope}
\node [font=\ttfamily, anchor=north, label=below:but not labels] at ([yshift=-5mm]current bounding box.south) {every node};
\end{tikzpicture}
\end{document}