tikz 节点有锚点south
,north
等等,还有south west
等等south east
......
但是在下图中,我想从一个节点画一条线,该线不是从 开始,而是从和south west
中间开始。即从西南角向右移动更多,以便看起来更好。south west
south
通常,如何创建一个新的锚点位置来绘制除建筑物之外的线条?
举个例子就清楚了。这个 MWE
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\begin{document}
\pagestyle{empty}
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}
% Place nodes
\node [block] (init) {differential equation};
%
\node [block, below right=1cm and -1.5cm of init] (secondOrder) {second order};
%
\node [block, below=1cm of secondOrder] (linearSecondOrder) {linear};
\node [block, right=1cm of linearSecondOrder] (nonlinearSecondOrder) {non-linear};
%
\node [block, below left=1cm and 1cm of init] (firstOrder) {first order};
%
\node [block, below=1cm of firstOrder] (firstOrderDegree1) {degree 1};
%
\node [block, below right=.5cm and -1.2cm of firstOrderDegree1] (linearFirstOrder) {linear};
\node [block, below=.5cm of linearFirstOrder] (separable) {separable};
\node [block, below=.5cm of separable] (bernoulli) {Bernoulli};
%
\node [block, left=1cm of firstOrderDegree1] (firstOrderDegreeHigher) {higher degree};
%
\node [block, below right=1cm and 4.5cm of init] (higherOrder) {higher order};
\path [line] (init) -- (firstOrder);
\path [line] (init) -- (secondOrder);
\path [line] (init) -- (higherOrder);
%
\path [line] (secondOrder) -- (linearSecondOrder);
\path [line] (secondOrder) -- (nonlinearSecondOrder);
%
\path [line] (firstOrder) -- (firstOrderDegree1);
\path [line] (firstOrder) -- (firstOrderDegreeHigher);
%
\path [line] (firstOrderDegree1.south west) -- (linearFirstOrder.west);
\path [line] (firstOrderDegree1.south west) -- (separable.west);
\path [line] (firstOrderDegree1.south west) -- (bernoulli.west);
\end{tikzpicture}
\end{document}
生成此
实际上我想做的是以下几点,但我认为这比较难,所以我首先尝试看看是否可以先改变锚点位置:
上面的方法更好,但我不知道该怎么做,因为我不知道从哪里开始/到哪里画线。所以如果可能的话,我现在会选择第一个选择。
答案1
这是一个使用 的选项forest
。
\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={
draw, rounded corners, fill=blue!20,
minimum height=1.5cm, minimum width=2cm,
align=center, base=b,
s sep=1cm, l sep=.5cm,
if level<=2{edge=-latex}{edge=red},
}
[differential\\equation
[first order, calign=last
[higher\\degree][degree 1, for tree={grow'=0, folder}, s sep=.5cm, before computing xy={l-=.845cm}
[linear][separable][Bernoulli]
]
]
[second order, calign=first
[linear][nonlinear]
]
[higher order, fit=band]
]
\end{forest}
\end{document}