我使用 tikz 绘制了这张图表:
\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}
\pagestyle{empty}
\tikzstyle{line} = [draw, -latex']
\tikzstyle{block} = [rectangle, draw, fill=blue!20,
text width=5em, text centered, rounded corners, minimum height=4em]
\begin{tikzpicture}[node distance = 5cm, scale=0.1]
% Place nodes
\node [block](trr) {Node};
\node [block] (trr1) [below of=trr] {A};
\node [block] (trr2) [left of=trr1] {B};
\node [block] (trr3) [right of=trr1] {C};
%\node [block] (trr4) [right of=trr3] {D};
% Draw edges
\path [line] (trr) -- (trr1);
\path [line] (trr) -- (trr2);
\path [line] (trr) -- (trr3);
%\path [line] (trr) -- (trr4);
\end{tikzpicture}
\end{document}
我希望这个区块节点保持居中,并且我有 4 个元素(A,乙,C和德) 位于第二行。我该如何实现这一点?
取消注释该行
\node [block] (trr4) [right of=trr3] {D};
和
\path [line] (trr) -- (trr4);
答案1
你实际上画了一棵树..所以看看下面的代码是否给出了所需的结果:
\documentclass[border=3mm,
tikz]{standalone}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[
every node/.style = {rectangle, draw, rounded corners,
fill=blue!20,
text width=3em, minimum height=2em,
align=center},
edge from parent/.style= {draw, -latex'}
]
\node (trr) {Node}
child {node (trr1) {A}}
child {node (trr2) {B}}
child {node (trr3) {C}}
child {node (trr4) {D}};
\end{tikzpicture}
\end{document}
附录:五年后我注意到,你喜欢在节点北边的子节点处放置箭头。使用forest package
这个可以简单地实现:
\documentclass[border=3mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest}
for tree = {
% nodes
draw, rounded corners, fill=blue!20,
text width=3em, minimum height=2em, text centered,
% tree
child anchor = north,
edge={-Latex},
l sep=11mm,
s sep=1mm
}
[Node
[A] [B] [C] [D]
]
\end{forest}
\end{document}