我有一张想要重现的绘图,但我仍然无法很好地排列节点并使其正确居中。有人能帮我解决这个排列问题吗?这是我想要重现的绘图:
\documentclass[10pt,a4paper,oneside]{book}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}\begin{flushleft}
\begin{tikzpicture}
\tikzset{every node/.style=
{thick, draw=black, align=center, minimum height=50pt, text width=50pt}
}
\node(a1) {SALE};% start with left second level
\node[right=10pt] (a2) at (a1.east) {FINANCE};
\node[right=10pt] (a3) at (a2.east){WARE-\\HOUSE};
\node[right=10pt] (a4) at (a3.east) {M-PESA};
\node[right=10pt] (a5) at (a4.east) {EBU};
\node[right=10pt] (a6) at (a5.east) {MARKETING};
\node[right=10pt] (a7) at (a6.east) {OPERATION};
\node[right=10pt] (a8) at (a7.east) {CORPS SHOP\\VODASHOP};
\node[above=10pt] (top) at ($(a2.north)!.5!(a3.north)$) {Directeur de\\region};
%\node[below=20pt] (chini) at (top.north) {text};
\node[below=10pt] (b2) at (a2.south) {SALES};
\node[below=10pt] (b3) at (a3.south) {text};
\node[below=10pt] (b4) at (a4.south) {text};
\coordinate (atop) at ($(top.south) + (0,-5pt)$);% midpoint below top
%\coordinate (atop) at ($(top.north) + (0,-5pt)$);% midpoint below chini
\coordinate (btop) at ($(a3.south) + (0,-5pt)$);% midoint below a3
\draw[thick] (top.south) -- (atop)
%(chini.north) |- (atop) -| (a8.north)
(a1.north) |- (atop) -| (a8.north)
(a2.north) |- (atop) -| (a3.north)
(a3.south) -- (b3.north)
(b2.north) |- (btop) -| (b4.north);
\end{tikzpicture}
\end{flushleft}
\end{document}`
答案1
作为@SebGlav 答案的补充:
\documentclass[border=3.141592]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{positioning}
\tikzset{
node distance = 4mm and 0mm,
N/.style = {draw, thick, rounded corners=3pt,
inner sep=10pt}
}
\begin{document}
\begin{forest}
for tree={
% nodes styles
N,
if level={1}{fill=cyan!30}{fill=red!30},
% tree style
edge = {draw, thick},
anchor=north,
forked edge,
s sep=4mm,
l sep=24mm,
fork sep=18mm,
},
% tree body
[Directeur de région, name=DR
[SALES]
[FINANCE]
[WAREHOUSE]
[M-PESA]
[EBU]
[MARKETING]
[OPERATION]
[COPS SHOPS]
]
\node (RH) [N, fill=red!30,
below right=of DR] {RESSOURCES HUMAINES};
\draw[thick] (DR |- RH) -- (RH);
\end{forest}
\end{document}
答案2
\documentclass[border=3.14mm]{standalone}
\usepackage[edges]{forest}
\begin{document}
\tikzset{
every node/.style={ draw,black,thick,
rounded corners=3pt,
minimum height=30pt,
inner sep=10pt,},
chief/.style = {fill=cyan},
sub/.style = {fill=pink},
}
\forestset{
my tree/.style={
for tree={
forked edge,
edge = {draw, thick},
s sep=5mm,
l sep=5cm,
fork sep=4cm,
anchor=north,
text centered,
},
},
}
\begin{forest}
my tree
% tree starts here
[Directeur de région, name=DR, chief
[SALES, sub]
[FINANCE, sub]
[WAREHOUSE, sub]
[M-PESA, sub]
[EBU, sub]
[MARKETING, sub]
[OPERATION, sub]
[COPS SHOPS, sub]
]
\draw[thick] (DR.south) |-++ (2,-2) node[sub,right]{RESSOURCES HUMAINES};
\end{forest}
\end{document}
编辑:Plain Ti钾Z 解决方案,无任何包装
trees
这是一个没有森林、没有图书馆、没有的解决方案chains
,如果你只能做简单的 Ti钾现在的 Z 命令:
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{positioning,fit}
\tikzset{
every node/.style={ draw,black,thick,
rounded corners=3pt,
minimum height=30pt,
inner sep=10pt,},
chief/.style = {fill=cyan},
sub/.style = {fill=pink},
}
\begin{document}
\begin{tikzpicture}[node distance=5mm]
\node[sub](1){SALES};
\foreach \content [count=\i from 1] in {
FINANCE,
WAREHOUSE,
M-PESA,
EBU,
MARKETING,
OPERATION,
COPS SHOPS}
{
\pgfmathtruncatemacro\j{\i+1}
\node[sub,right=of \i](\j){\content};
}
\node[fit=(1)(8),draw=none](ens){};
\node[above=3cm of ens,chief](DR){DIRECTEUR DE RÉGION};
\draw[thick] (DR) --++ (0,-3) coordinate (aux);
\foreach \i in {1,...,8} \draw[thick] (aux) -| (\i);
\draw[thick] (DR) |-++ (2,-1.5) node[sub,right]{RESSOURCES HUMAINES};
\end{tikzpicture}
\end{document}