我正在寻找一种方法,在绘制树时默认使用正交边(仅水平和垂直)。我似乎找不到一种方法将其设置为默认样式(而不必每次都添加带路径的边)。
\documentclass{article}
\usepackage{tikz}
%%% <
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{10pt}%
%%% >
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\begin{document}
\begin{tikzpicture}
\tikzstyle{every node}=[draw, rectangle, fill=gray!20]
\node {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\end{tikzpicture}
\end{document}
我已附上我正在搜索的边缘的示例。边缘上不需要标签。
答案1
您可以根据需要进一步调整
\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc}
\begin{document}
\begin{tikzpicture}[
every node/.style={draw, rectangle, fill=gray!20},
edge from parent path={
(\tikzparentnode) |- % Start from parent
($(\tikzparentnode)!0.5!(\tikzchildnode)$) -| % make an ortho line to mid point
(\tikzchildnode)}] % make another ortho to the target
\node {root}
child {node {left}}
child {node {right}
child {node {child}}
child {node {child}}
};
\end{tikzpicture}
\end{document}