我基本上希望将其延伸得scope
更远一些,以便它不会碰到节点或阴影。
父节点和中间子节点之间还有一个微小的“勾号”,我不知道如何将其删除。
\documentclass{article}
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{arrows.meta,shapes.geometric,shadows,shadings,positioning,matrix,calc,backgrounds,fadings}
\tikzfading[name=fade right,
left color=transparent!0,
right color=transparent!100]
\usepackage{fontawesome5}
\usepackage{xcolor-material}
\usepackage{graphicx}
\usepackage[sfdefault]{FiraSans}
\colorlet{cinza}{MaterialGrey600}
\colorlet{vermelho}{MaterialRed400}
\usepackage[edges]{forest}
\usetikzlibrary{fit}
\begin{document}
\begin{forest}
for tree={
fill=cinza,rounded corners,align=center,rectangle,
drop shadow,text=white,inner sep=6pt,l sep=.6cm,
fork sep=.3cm,
%line width=1pt,
%draw=MaterialYellow800,
edge={thick, draw=cinza, rounded corners=1pt},
},
for 1={fork sep = .6cm},
for 3={fork sep = .6cm},
forked edges,
[Presidente,before drawing tree={x+=1.29cm}, l sep+=2em,fill=MaterialOrange600,
[Departamento\\Comercial
[Ger. Marketing]
[Ger. Vendas]
]
[Departamento\\de Produção
[Ger. Produção]
[Ger. Compras]
]
[Departamento\\Financeiro,before drawing tree={x+=2.5cm}]
]
\begin{scope}[on background layer]
\fill[top color=MaterialGreen400,bottom color=MaterialGrey200,inner ysep=1em, inner xsep=1em, outer sep=1pt,%path fading=fade right
rounded corners
]
(current bounding box.north west) rectangle (current bounding box.south east);
\end{scope}
\end{forest}
\end{document}
答案1
shadow xshift
你可以通过和 来扩展拟合shadow yshift
。这是通过 中的移位实现的
(current bounding box.north west) rectangle
([yshift=-0.5ex,xshift=0.5ex]current bounding box.south east);
然后,您的树包含一些节点的移位,这对于早期版本来说可能足够了。为了找出您需要的移位,请删除
before drawing tree={x+=36.06616pt}
从根节点键入并取消注释
\path let \p1=($(dep)-(pres)$) in \pgfextra{\typeout{\x1}};
这将告诉您需要移动的精确尺寸。
\documentclass{article}
\usepackage[margin=1in]{geometry}%<- to make the page fit the tree
\usepackage{tikz}
\usepackage{tikzpagenodes}
\usetikzlibrary{fit,shadows,fadings,backgrounds}
\tikzfading[name=fade right,
left color=transparent!0,
right color=transparent!100]
\usepackage{fontawesome5}
\usepackage{xcolor-material}
\usepackage[sfdefault]{FiraSans}
\colorlet{cinza}{MaterialGrey600}
\colorlet{vermelho}{MaterialRed400}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
for tree={anchor=center,%<-added
fill=cinza,rounded corners,align=center,rectangle,
drop shadow,text=white,inner sep=6pt,l sep=.6cm,
fork sep=.3cm,
%line width=1pt,
%draw=MaterialYellow800,
edge={thick, draw=cinza, rounded corners=1pt},
},
for 1={fork sep = .6cm},
for 3={fork sep = .6cm},
forked edges,
[Presidente, l sep+=2em,before drawing tree={x+=36.06616pt},fill=MaterialOrange600,alias=pres
[Departamento\\Comercial
[Ger. Marketing]
[Ger. Vendas]
]
[Departamento\\de Produc\~ao,alias=dep
[Ger. Produc\~ao]
[Ger. Compras]
]
[Departamento\\Financeiro,before drawing tree={x+=2.5cm}]
]
% restore this if you need to readjust the position of the root node
%\path let \p1=($(dep)-(pres)$) in \pgfextra{\typeout{\x1}};
\begin{scope}[on background layer]
\fill[top color=MaterialGreen400,bottom color=MaterialGrey200,inner ysep=1em, inner xsep=1em, outer sep=1pt,%path fading=fade right
rounded corners
]
(current bounding box.north west) rectangle
([yshift=-0.5ex,xshift=0.5ex]current bounding box.south east);
\end{scope}
\end{forest}
\end{document}
如果你让边界框更大,例如使用
\fill[top color=MaterialGreen400,bottom color=MaterialGrey200,inner ysep=1em, inner xsep=1em, outer sep=1pt,%path fading=fade right
rounded corners
]
([xshift=-1em,yshift=1em]current bounding box.north west) rectangle
([yshift=-0.5ex-1em,xshift=0.5ex+1em]current bounding box.south east);
你会得到
答案2
这是由纯 TikZ 手工制作的阴影节点。
\documentclass[tikz,border=0mm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}[n/.style={rounded corners,align=center,minimum height=1.2cm,minimum width=3.5cm,font=\sffamily,text=white}]
\def\shadowednode#1#2#3#4{
\path #1 node[n,fill=gray!50,shift={(.2,-.15)}]{#2}
node[n,fill=#4] (#3) {#2};
}
\shadowednode{(0,0)}{University of \\Natural Sciences}{NS}{orange}
\shadowednode{(0,-2.5)}{Department of\\ Mathematics}{M}{brown}
\shadowednode{(5,-2.5)}{Department of\\ Physics}{P}{brown}
\shadowednode{(-5,-2.5)}{Department of\\ Biology}{B}{brown}
\draw
(NS.south)--(M.north)
(NS.south)--++(-90:.5)-|(B.north)
(NS.south)--++(-90:.5)-|(P.north);
\begin{scope}[on background layer]
\fill[top color=green!50,bottom color=teal]
(current bounding box.south west)+(-.5,-.5)
rectangle
([shift={(.5,.5)}]current bounding box.north east);
\end{scope}
\end{tikzpicture}
\end{document}