如果这是一个愚蠢的问题,请原谅 - 这是我在 stackexchange 上的第一个问题。我使用 forest 包构建了下面的树。不幸的是,这棵树对于页面来说太“宽”了。
有没有办法让森林将粉色框放在绿色框下方的长线上,以便树适合页面?或者你能想出一种方法来排版此图,使其水平适合而不会看起来太“挤压”吗?
谢谢!
\documentclass{article}
\usepackage{forest}
\usepackage{tikz}
\usetikzlibrary{shadows,arrows.meta}
%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
l sep=0.6cm,
s sep=0.8cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=green!30} %Format everything below here as children
[Sub distributor
[Agent
[Customer] {\draw[->,dotted] () to[out=north,in=north west] (Company);}
[Installer]
[Installer]
]
[Agent]
]
[Sub distributor
[Agent]
[Agent]
]
]
[Distributor, for tree={child, fill=pink!50}
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
[Sub distributor]
]
]
\end{forest}
\end{document}
答案1
您可以调整text width
节点,也可以调整l
anss sep
以使节点更接近。进一步添加,交换 Sub distributor
节点。不过,您必须稍微修改虚线箭头。
\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
l sep=1cm,
s sep=0.1cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=green!30} %Format everything below here as children
[Sub distributor
[Agent]
[Agent]
]
[Sub distributor,
[Agent,
[Customer] {\draw[->,dotted] () -- ++(-4cm,0) to[out=north,in=west] (Company);}
[Installer]
[Installer]
]
[Agent]
]
]
[Distributor, for tree={child, fill=pink!50}
[Sub distributor]
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
]
]
\end{forest}
\end{document}
我希望这足以将内容带入页面;-)。
通过s=1cm
使用
[Company,s=1cm, name=Company,...
可以调整绿色和粉色团伙之间的水平间距,以获得
但它又会增加总宽度(这正是我们试图减少的!)。
将粉色向左移动将得到
\documentclass{article}
\usepackage{forest}
\usetikzlibrary{shadows,arrows.meta}
%Defining the styles used in trees
%Note that the fill colour is not defined here.
\tikzset{parent/.style={align=center,text width=2cm,rounded corners=2pt},
child/.style={align=center,text width=2cm,rounded corners=6pt},
grandchild/.style={text width=2.3cm}
}
\begin{document}
\begin{forest}
for tree={%
l sep=1cm,
s sep=0.1cm,
minimum height=0.8cm,
minimum width=2cm,
draw %Put lines around each
}
[Company, name=Company, parent, fill=blue!30
[Distributor, for tree={child, fill=pink!50}
[Sub distributor
[Installer
[Customer] {\draw[<->] () to[out=east,in=south] (Scratch);}
]
[Scratchcard reseller, name=Scratch]
]
[Sub distributor]
]
[Distributor, for tree={child, fill=green!30} %Format everything below here as children
[Sub distributor
[Agent]
[Agent]
]
[Sub distributor,
[Agent,
[Customer] {\draw[->,dotted] () --++(0,-1cm) -- ++(6.5cm,0) to[out=north,in=east] (Company);}
[Installer]
[Installer]
]
[Agent]
]
]
]
\end{forest}
\end{document}
正如所见,情况并没有太大改善。