如何直接在 LaTeX 中创建这个流程图?

如何直接在 LaTeX 中创建这个流程图?

在此处输入图片描述

是否可以使用 forest 或 tikz 创建流程图?

答案1

这是我重新创建图表的尝试。这可能不是最优雅的解决方案,因为它包含大量手动节点移动,但它应该可以作为起点。

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning,shapes,arrows,fit,decorations,decorations.text,calc,decorations.pathreplacing}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{palatino}

\begin{document}
    \begin{tikzpicture}[
        block/.style={draw,thick,rectangle,minimum height=2cm,minimum width=3cm,font=\bfseries,align=center,text width=2.5cm},
        number/.style={draw,circle,minimum size=7mm,inner sep=3pt},
        arrow/.style={draw,thick,->,>=stealth},
        numarrow/.style={arrow,shorten >=.2cm,shorten <=.2cm},
        node distance = 2cm]
        \clip (-3.5cm,-6cm) rectangle ++(14.7cm,12.5cm);
        
        \begin{scope}[node distance = .75cm]
            \node[number] (three) {3};
            \node[number,above=of three] (two) {2};
            \node[number,above=of two] (one) {1};
            \node[below=of three] (dots) {\vdots};
            \node[number,below=of dots] (n) {n};
            \node[draw,red,thick,dash dot,ellipse,fit={(one) (n)}] (ellipse) {};
            \node[above = of ellipse, font=\bfseries,yshift=-.75cm] {agent};
        \end{scope}
    
        \node[block,xshift=4cm] at (three.east) (coord) {Coordinator};
        \node[block,right=of coord] (global) {Global Parameters};
        
        \draw[arrow] (coord) -- (global) node[anchor=south,midway,font=\small]{$\frac1n\sum\Delta\theta$} node[anchor=north,midway,font=\small] {$\frac1n\sum\Delta w$};
        
        
        \draw[decoration={text along path,text={Update {$\theta$}, w},text align={center},raise=1mm,reverse path},decorate] (global) to[out=290,in=350] (ellipse.south);
    \draw[arrow,red,dashed,shorten >=.3cm] (global) to[out=290,in=350] (ellipse.south);
        
        \foreach \i in  {one, two, three, n} {
            \draw[numarrow] (\i) -- (coord) node[anchor=south,font=\footnotesize,midway,sloped] {$\Delta\theta$, $\Delta$ w};
            \draw[arrow,<-] ($(\i.west)+(-3mm,2mm)$) -- ++(-1.5cm,0) node[anchor=south,midway,font=\small] {$r, s_{t+1}$};
            \draw[arrow] ($(\i.west)+(-3mm,-2mm)$) -- ++(-1.5cm,0) node[anchor=north,midway,font=\small] {$a$};
        }
    
        \draw [decoration={brace,amplitude=10pt},decorate] ($(one.north east)+(2mm,0)$) -- ++(2.5cm,0cm) node[midway,anchor=south,font=\footnotesize,text width=2cm,align=center,minimum height=1.5cm] {synchronous update};
        \node[draw, thick, minimum width=8cm, minimum height=1.0cm, rectangle, rotate=90, left = of three, anchor=south,font=\bfseries] {Environment};
    \end{tikzpicture}
\end{document}

输出图像

相关内容