我正在使用forest
TeX 中的包:
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{forest,array}
\usetikzlibrary{shadows}
\begin{document}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\begin{forest}
for tree={
if level=0{align=center}{% allow multi-line text and set alignment
align={@{}C{45mm}@{}},
},
draw,
font=\sffamily\bfseries,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5mm) -| (.child anchor)\forestoption{edge label};
},
parent anchor=south,
child anchor=north,
l sep=10mm,
tier/.wrap pgfmath arg={tier #1}{level()},
edge={ultra thick, rounded corners=2pt},
inner color=white,
outer color=white,
rounded corners=2pt,
drop shadow,
}
[UML Diagram
[Structure Diagram
[Class Diagram]
[Object Diagram]
[Package Diagram]
[Component Diagram]
[Composite Structure Diagram]
[Deployment Diagram]
[Profile Diagram]
]
[Behaviour Diagram
[Use Case Diagram]
[Activity Diagram]
[State Machine Diagram]
[Interaction Diagram
[Sequence Diagram]
[Communication Diagram]
[Interaction Overview Diagram]
[Timing Diagram]
]
]
]
\end{forest}
\end{document}
此代码产生
我喜欢使用forest
,但对于这种数据,它效果不太好。我需要转置/翻转/旋转图表,以便它使用页面的长度而不是宽度。因此,我需要将节点放在彼此下方,而不是彼此相邻。
我可以在包中做一些聪明的事情forest
来翻转它吗?我在文档中搜索了示例,但什么也没找到。
答案1
您可以使用密钥grow=east
,然后更改一些内容以适应这一点:
- 父母与子女锚
- 边标签计算
我还改变了颜色,fill=white
因为您的选项使节点看起来是灰色的。
输出
代码
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{forest,array}
\usetikzlibrary{shadows}
\begin{document}
\newcolumntype{C}[1]{>{\centering}p{#1}}
\begin{forest}
for tree={
if level=0{align=center}{% allow multi-line text and set alignment
align={@{}C{45mm}@{}},
},
grow=east,
draw,
font=\sffamily\bfseries,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(5mm,0) |- (.child anchor)\forestoption{edge label};
},
parent anchor=east,
child anchor=west,
l sep=10mm,
tier/.wrap pgfmath arg={tier #1}{level()},
edge={ultra thick, rounded corners=2pt},
fill=white,
rounded corners=2pt,
drop shadow,
}
[UML Diagram
[Structure Diagram
[Class Diagram]
[Object Diagram]
[Package Diagram]
[Component Diagram]
[Composite Structure Diagram]
[Deployment Diagram]
[Profile Diagram]
]
[Behaviour Diagram
[Use Case Diagram]
[Activity Diagram]
[State Machine Diagram]
[Interaction Diagram
[Sequence Diagram]
[Communication Diagram]
[Interaction Overview Diagram]
[Timing Diagram]
]
]
]
\end{forest}
\end{document}