帮助流程图对齐

帮助流程图对齐

有人可以帮忙对齐两个背景层框,使它们彼此居中吗?

\begin{tikzpicture}[
        scale = 0.85,
        transform shape,
        bend angle     = 0,
        node distance  = 10mm,
        hollow/.style  = {circle, draw = black, semithick, inner sep = 0pt, minimum size = 11mm},
        filled/.style  = {rectangle, draw = blue, dotted, minimum size = 13mm, inner sep = 0.3 cm,  fill=blue!10!white},
        invisi/.style  = {rectangle, draw = white, minimum size = 11mm},
        invisi2/.style  = {rectangle, draw = black!10!white, minimum size = 11mm},
        myright/.style = {<-, shorten < = 1pt, bend right, semithick},
        myleft/.style  = {->, shorten > = 1pt, bend left, semithick},
        mydown/.style  = {<-, shorten < = 1pt, bend left, semithick},
        myup/.style    = {->, shorten > = 1pt, bend right, semithick}
    ]
    
    \node[invisi2,align=center] (naive_forecast)                 {Naive};
    \node[invisi2,align=center, node distance = 15mm] (xgb)  [right=of naive_forecast] {XGBoost};
    \node[invisi2,align=center, node distance = 15mm] (nhits)  [right=of xgb] {NHiTS};
    \node[invisi2,align=center, node distance = 15mm] (mdn)  [right=of nhits] {Mixed Density Networks};
    
      \begin{scope}[on background layer]
        \node[draw = blue, dotted, inner sep=0.3cm, fill=blue!10!white, fit=(naive_forecast) (mdn), label = above: {\footnotesize \textit{\textcolor{blue}{Demand Forecasting}}}](forecast) {};
        \end{scope}
        
    
    \node[invisi2,align=center, node distance = 15mm] (greedy)  [below=of forecast] {Greedy};
    % edge [mydown] node[auto, swap] {} (forecast);
    \node[invisi2,align=center, node distance = 15mm] (naive_dec)  [left=of greedy] {Naive};
    \node[invisi2,align=center, node distance = 15mm] (mdp)  [right=of greedy] {Markov Decision Process};
    
    \begin{scope}[on background layer]
        \node[draw = blue, dotted, inner sep=0.3cm, fill=blue!10!white, fit=(naive_dec) (mdp), label = below: {\footnotesize \textit{\textcolor{blue}{Driver Allocation}}}](driver_all) {}
        edge [mydown] node[auto, swap] {} (forecast);
        \end{scope}

\end{tikzpicture}

答案1

欢迎来到 TeX.SE!

这就是你所追求的吗?

在此处输入图片描述

梅威瑟:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                chains,
                fit,
                positioning}
\newsavebox{\Second}

\begin{document}
    \begin{tikzpicture}[
node distance =  12mm and 8mm,
  start chain = A going right,
F/.style args = {#1/#2}{draw, densely dotted, semithick, 
                 fill=blue!30!white, , fill opacity=0.3,
                        inner xsep=0pt, outer sep=2pt, 
                        label={[font=\itshape, text=blue]#1},
                        fit = #2},
  N/.style = {inner xsep=3mm, on chain=A},
arr/.style = {-Straight Barb, ultra thick},
                    ]

\node[N]    {Naive};                    % A-1
\node[N]    {XGBoost};
\node[N]    {NHiTS};
\node[N]    {Mixed Density Networks};   % A-4
\node[F=Demand Forecasting/(A-1) (A-4)] (f1) {};

\savebox{\Second}{\tikz[inner ysep=0pt]{%
\node[N]    {Greedy};     % A-5
\node[N]    {Naive};
\node[N]    {Markov Decision Process};  % A-7
                  }}
\node[below=of f1] (sb) {\usebox{\Second}};
\node[F=below:Driver Allocation/(sb)] (f2) {}; 

\draw[arr]  (f1) -- (f2);
    \end{tikzpicture}
\end{document}

相关内容