LaTeX 流程图错误

LaTeX 流程图错误

在此处输入图片描述

我正在生成此图像并遇到了这个 LaTeX 代码,但是当我运行它时它会使图像变平。

% Flowchart
% Author: Qrrbrbirlbel
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{shapes.geometric,backgrounds,
  positioning-plus,node-families,calc}
\tikzset{
  basic box/.style = {
    shape = rectangle,
    align = center,
    draw  = #1,
    fill  = #1!25,
    rounded corners},
  header node/.style = {
    Minimum Width = header nodes,
    font          = \strut\Large\ttfamily,
    text depth    = +0pt,
    fill          = white,
    draw},
  header/.style = {%
    inner ysep = +1.5em,
    append after command = {
      \pgfextra{\let\TikZlastnode\tikzlastnode}
      node [header node] (header-\TikZlastnode) at (\TikZlastnode.north) {#1}
      node [span = (\TikZlastnode)(header-\TikZlastnode)]
        at (fit bounding box) (h-\TikZlastnode) {}
    }
  },
  hv/.style = {to path = {-|(\tikztotarget)\tikztonodes}},
  vh/.style = {to path = {|-(\tikztotarget)\tikztonodes}},
  fat blue line/.style = {ultra thick, blue}
}
\begin{document}
\begin{tikzpicture}[node distance = 1.2cm, thick, nodes = {align = center},
    >=latex]
  \node[Minimum Width = loop, shape = ellipse, fill = red] (imp-sol)
    {ellipsoid box};
  \node[Minimum Width = loop, fill = yellow, below = of imp-sol] (rec-box)
    {rectangular box, and very wiiiiiiiiiiiiiiide\\2nd line};
  \node[shift = (left:.5*x_node_dist)] at
    ($(imp-sol.west|-imp-sol.south)!.5!(rec-box.north west)$) (for-1)
    {formula 1};
  \node[shift = (right:.5*x_node_dist)] at
    ($(imp-sol.east|-imp-sol.south)!.5!(rec-box.north east)$) (for-2)
    {formula 2};
  \begin{scope}[on background layer]
    \node[fit = (for-1)(for-2)(imp-sol)(rec-box), basic box = blue,
      header = DMFT loop] (dmft-l) {};
  \end{scope}
  \path[very thick, blue, hv] (rec-box) edge[->] (for-1) edge[<-] (for-2)
                              (imp-sol) edge[->] (for-2) edge[<-] (for-1);

  \node[east above = of dmft-l, basic box = green, header = DMFT prelude]
    (dmft-p) {Math and text math and text math and text\\
              math and text math and text math and text};
  \node[north left = of dmft-l, basic box = green, header = $\rho$ update,
     shift = (down:y_node_dist)] (rho)
    {Much more text much more text\\much more text much more text};
  \node[basic box = blue, header = DFT part, anchor = north] at
    (dmft-p.north-|rho) (dft) {So much text so much text so much text\\
    I think I need \texttt{tikz-lipsum}\\or something like that.};
  \node[basic box = green, anchor = north] at
    ($(dft.north east)!.5!(dmft-p.north west)$) (upd) {update\\$math$};
  \path[fat blue line, <-, dashed, vh] (rho) edge
    ({$(rho.south)!.5!(dmft-l.south)$}-|dmft-l.south west);
  \path[fat blue line, ->]
    ({$(upd.south)!.5!(dmft-p.south)$}-|dmft-p.south west)
    coordinate (@) edge[<-, solid] coordinate[pos=.15] (@s)
    coordinate[pos=.9] (@e) (@-|dft.east)
    {[every edge/.append style=dashed, vh] (@s) edge[<-] (upd) (@e) edge (upd)}
    (h-rho) edge[dashed] (dft)
    ($(dmft-p.south)!.5!(dmft-p.south east)$)
    coordinate (@) edge (@|-dmft-l.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

只是为了好玩:有些人试图添加一些有点让人联想到的功能positioning-plus。这无法与图书馆竞争,但足以或多或少地重现图表,

\documentclass[tikz,border=10pt]{standalone}
\usepackage{eqparbox}
\newbox\eqnodebox
\tikzset{equal size/.style={execute at begin
    node={\setbox\eqnodebox=\hbox\bgroup},
    execute at end node={\egroup\eqmakebox[#1][c]{\copy\eqnodebox}}},
    equal size/.default=A}
\makeatletter
\pgfmathdeclarefunction{widthofeqsizenode}{1}{\begingroup%
\ifcsname eqp@this@#1\endcsname
\edef\pgfutil@tempx{\csname eqp@this@#1\endcsname}%
\else
\edef\pgfutil@tempx{0pt}%
\fi
\pgfmathparse{\pgfutil@tempx+2*\pgfkeysvalueof{/pgf/inner xsep}}%
\pgfmathsmuggle\pgfmathresult\endgroup%
}
\makeatother    

\usetikzlibrary{backgrounds,calc,fit,positioning,shapes.geometric}
\tikzset{
  basic box/.style = {
    shape = rectangle,
    align = center,
    draw  = #1,
    fill  = #1!25,
    rounded corners},
  header node/.style = {
    equal size= header nodes,
    font          = \strut\Large\ttfamily,
    text depth    = +0pt,
    fill          = white,
    draw},
  header/.style = {%
    inner ysep = +1.5em,
    append after command = {
      \pgfextra{\let\TikZlastnode\tikzlastnode}
      node [header node] (header-\TikZlastnode) at (\TikZlastnode.north) {#1}
    }
  },
  east above/.style args={#1of#2}{above=#1 of #2.north east,anchor=south east},
  west above/.style args={#1of#2}{above=#1 of #2.north west,anchor=south west},
  east below/.style args={#1of#2}{below=#1 of #2.south east,anchor=north east},
  west below/.style args={#1of#2}{below=#1 of #2.south west,anchor=north west},
  north left/.style args={#1of#2}{left=#1 of #2.north west,anchor=north east},
  north right/.style args={#1of#2}{right=#1 of #2.north east,anchor=north west},
  south left/.style args={#1of#2}{left=#1 of #2.south west,anchor=south east},
  south right/.style args={#1of#2}{right=#1 of #2.south east,anchor=south west},
  hv/.style = {to path = {-|(\tikztotarget)\tikztonodes}},
  vh/.style = {to path = {|-(\tikztotarget)\tikztonodes}},
  fat blue line/.style = {ultra thick, blue}
}
\begin{document}
\begin{tikzpicture}[node distance = 1.2cm, thick, nodes = {align = center},
    >=latex]
  \node[minimum width={widthofeqsizenode("loop")}, 
  shape = ellipse, fill = red] (imp-sol)
    {ellipsoid box};
  \node[equal size=loop, fill = yellow, below = of imp-sol] (rec-box)
    {rectangular box, and very wiiiiiiiiiiiiiiide\\2nd line};
  \path (imp-sol.west) --   (rec-box.west) node[pos=0.5,left]
    (for-1)   {formula 1}
      (imp-sol.east) --     (rec-box.east) node[pos=0.5,right]
    (for-2)    {formula 2};
  \begin{scope}[on background layer]
    \node[fit = (for-1)(for-2)(imp-sol)(rec-box), basic box = blue,
      header = DMFT loop] (dmft-l) {};
  \end{scope}
  \path[very thick, blue, hv] (rec-box) edge[->] (for-1) edge[<-] (for-2)
                              (imp-sol) edge[->] (for-2) edge[<-] (for-1);
  \node[east above=of dmft-l, basic box = green,
    header = DMFT prelude] (dmft-p) {Math and text math and text math and text\\
    math and text math and text math and text};
  \node[basic box=green,north left=of dmft-p] (upd) {update\\$math$};
  \node[basic box=blue, header=DFT part,north left=of upd] 
     (dft) {So much text so much text so much text\\
    I think I need \texttt{tikz-lipsum}\\or something like that.};
  \node[basic box = green, header = $\rho$ update]  (rho)
   at (dft|-dmft-l)
    {Much more text much more text\\much more text much more text};
  \path[fat blue line, <-, dashed, vh] (rho) edge
    ({$(rho.south)!.5!(dmft-l.south)$}-|dmft-l.south west);
   \path[fat blue line, ->]
    ([yshift=1em]dmft-p.south west) coordinate (auxR) edge[<-]
    (auxR-|dft.east) (auxR-|dft.east) coordinate (auxL)
   (upd.west) edge[<-,dashed,hv] ([xshift=5mm]auxL)
   (upd.east) edge[dashed,hv] ([xshift=-5mm]auxR)
     (header-rho) edge[dashed] (dft)
     ([xshift=-1cm]dmft-p.south east) coordinate (aux) edge (aux|-dmft-l.north);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

渴望评论:

测试您的 MWE 我得到了正确的节点位置,但是文本不可见。我需要\text=black向所有节点添加样式定义。这样做,我稍微缩短了样式名称并重新组织了箭头的绘制:

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{backgrounds,
                calc,
                node-families,
                positioning-plus,
                shapes.geometric,}
\tikzset{
       box/.style = {draw=#1, rounded corners, fill=#1!25,
                     align = center, text=black, inner ysep=1.5em},
        HN/.style = {draw, fill=white,
                     Minimum Width=header nodes,
                     font=\Large\ttfamily, text=black,
                     text depth=0.5ex, text height   = 2ex},
   header/.style = {%inner ysep = +1.5em,
                    append after command = {\pgfextra{\let\LN\tikzlastnode}
                        node [HN] (header-\LN) at (\LN.north) {#1}
                        node (h-\LN) [span=(\LN)(header-\LN)] at (fit bounding box){}
                                            }
                    },
  hv/.style = {to path = {-|(\tikztotarget)\tikztonodes}},
  vh/.style = {to path = {|-(\tikztotarget)\tikztonodes}},
  fat blue line/.style = {ultra thick, blue}
        }
\begin{document}
    \begin{tikzpicture}[
node distance = 1.2cm, thick, 
        nodes = {align = center},
            > = latex]
\node[Minimum Width = loop, shape = ellipse, fill = red, text=black] (imp-sol) {ellipsoid box};
\node[Minimum Width = loop, fill = yellow, text=black, below = of imp-sol] (rec-box)
    {rectangular box, and very wiiiiiiiiiiiiiiide\\2nd line};

  \node[shift = (left:.5*x_node_dist)] at
    ($(imp-sol.west|-imp-sol.south)!.5!(rec-box.north west)$) (for-1)
    {formula 1};
  \node[shift = (right:.5*x_node_dist)] at
    ($(imp-sol.east|-imp-sol.south)!.5!(rec-box.north east)$) (for-2)
    {formula 2};
\scoped[on background layer]
    \node[fit = (for-1)(for-2)(imp-sol)(rec-box), box = blue, 
      header = DMFT loop] (dmft-l) {};
%
  \path[very thick, blue, hv] (rec-box) edge[->] (for-1) edge[<-] (for-2)
                              (imp-sol) edge[->] (for-2) edge[<-] (for-1);
%%%
\node[east above = of dmft-l, box = green, header = DMFT prelude]
    (dmft-p) {Math and text math and text math and text\\
              math and text math and text math and text};
\node[north left = of dmft-l, box = green, header = $\rho$ update,
     shift = (down:y_node_dist)] (rho)
    {Much more text much more text\\much more text much more text};
\path[fat blue line, <-, dashed, vh] (rho) edge
    ({$(rho.south)!.5!(dmft-l.south)$} -| dmft-l.south west);
%%%
\node[box = blue, header = DFT part, anchor = north] at
    (dmft-p.north-|rho) (dft) 
    {So much text so much text so much text\\
    I think I need \texttt{tikz-lipsum}\\or something like that.};
%%%
\node[box = green, inner sep=3pt, below] at
    ($(dft.north east)!.5!(dmft-p.north west)$) (upd) {update\\$math$};
\draw[fat blue line, <-]
    ($(upd.south -| dmft-p.west)!0.5!(dmft-p.south west)$) coordinate (@) 
                --  coordinate[pos=.15] (@s)
                    coordinate[pos=.9]  (@e) (@ -| dft.east);
    %
    \begin{scope}[fat blue line, dashed, ->]
\draw   (upd) -| (@s);
\draw   (upd) -| (@e) 
%
        (h-rho) edge    (dft)
        ($(dmft-p.south)!.5!(dmft-p.south east)$) coordinate    (@) 
                -- (@ |- dmft-l.north);
    \end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

为了获得上述结果,您需要至少编译 MWE 两次。

相关内容