How to extend background fill color scope for a tree?
You could just extend the fit by the shadow xshift
and shadow yshift
. This is what is done with the shifts in
(current bounding box.north west) rectangle
([yshift=-0.5ex,xshift=0.5ex]current bounding box.south east);
Then, your tree contains some shifts of the nodes, which where probably adequate for an earlier version. In order to find out which shift you need, remove the
before drawing tree={x+=36.06616pt}
key from the root node and uncomment
\path let \p1=($(dep)-(pres)$) in \pgfextra{\typeout{\x1}};
This will tell you the precise dimension by which you need to shift.
\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}
If you make the bounding box more generous, e.g. by using
\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);
you'll get
This is a hand-made shadowed node by plain 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}