这是我当前流程图的代码。
\documentclass{article}
\usepackage{tikz,tkz-berge,tkz-graph}
\usetikzlibrary{graphs, graphs.standard, shapes.geometric, arrows, decorations.pathreplacing, positioning, quotes}
\begin{document}
\begin{figure}[htbp!]
\centering
\begin{tikzpicture}
\tikzstyle{rectlong} = [draw,rectangle,fill=white!20,text width=10em,text centered,minimum height=1.75em]
\tikzstyle{rectshort} = [draw,rectangle,fill=white!20,text width=5em,text centered,minimum height=1.75em]
\tikzstyle{rectultralong} = [draw,rectangle,fill=white!20,text width=19.5em,text centered,minimum height=1.75em]
\tikzstyle{rectmed} = [draw,rectangle,fill=white!20,text width=15em,text centered,minimum height=1.75em]
\node[rectlong,rounded corners](A){\small User input};
\node[rectlong,rounded corners,below left=0.75cm and 1.2cm of A](B){\small terrain map};
\node[rectlong,rounded corners,below=0.5cm of B](E){\small vertex-weighted grid graph $G$};
\node[rectshort,rounded corners,below=1.5cm of E](G){\small $c^2=\left[\ldots\right]$};
\node[rectshort,rounded corners,left=0.5cm of G](F){\small $c^1=\left[\ldots\right]$};
\node[rectshort,rounded corners,right=0.5cm of G](H){\small $c^3=\left[\ldots\right]$};
\node[rectshort,rounded corners,below=0.5cm of G](J){\small $\hat{c}^2=\left[\ldots\right]$};
\node[rectshort,rounded corners,left=0.5cm of J](I){\small $\hat{c}^1=\left[\ldots\right]$};
\node[rectshort,rounded corners,right=0.5cm of J](K){\small $\hat{c}^3=\left[\ldots\right]$};
\node[rectshort,rounded corners,right=0.5cm of K](C){\small $\mathbf{w}=(w_1,w_2,w_3)$};
\node[rectlong,rounded corners,below=1.2cm of K](L){\small grid graph with weighted sum cost $G'$};
\node[rectshort,rounded corners,right =2.5cm of L](D){\small $\Lambda=\langle v_s,\ldots,v_t\rangle$};
\node[rectmed,rounded corners,below =10cm of A](M){\small Complete graph $K_{n+2}$};
\node[rectmed,rounded corners,below =1cm of M](N){\small Best complete graph $\pi_{st}^*$};
\node[rectmed,rounded corners,below =1cm of N](O){\small Improved best $\pi_{st}^*$};
\node[rectmed,rounded corners,below =1cm of O](P){\small List of Pareto Optimal $\pi_{st}^*$ corresponds to different $\mathbf{w}$};
\node[draw, diamond,aspect=4.5,below=0.5cm of P,align=center](Q){\small User provide limit\\\small constraints?};
\node[rectshort,rounded corners,below left=0.5cm and 1.5cm of Q](R){\small $\varepsilon$-constraint method};
\node[rectshort,rounded corners,below right=0.5cm and 1.5cm of Q](S){\small Ideal point method};
\node[rectlong,rounded corners,below=1.5cm of Q](T){\small Final solution for user};
%simple arrow
\foreach \x/\y in {A/C, B/E, P/Q} \draw[->,thick](\x)--(\y);
%bended arrow
\foreach \from/\height/\to in {A.south/-4/B.north, A.south/-4/D.north, E.south/-12/F.north, E.south/-12/H.north, C.south/-4/L.north, I.south/-5.3/L.north, J.south/-5.3/L.north, D.south/-4/M.north, R.south/-2/T.north, S.south/-2/T.north}
\draw[->,thick](\from) |- ++(0,\height mm) -| (\to);
%bended labelled arrow
\draw[->,thick] (L.south) |- ++(0,-4.1mm) -| (M.north) node[right,pos=0.75,align=left] {\footnotesize perform Dijkstra's or A* \\\footnotesize algorithm $\forall v_i,v_j\in\Lambda$};
\draw[->,thick] (Q.west) |- ++(0,0mm) -| (R.north) node[above, pos=0.25] {\footnotesize yes};
\draw[->,thick] (Q.east) |- ++(0,0mm) -| (S.north) node[above, pos=0.25] {\footnotesize no};
%labelled arrow
\draw[->,thick](E)--(G)node[right,pos=0.35,align=left]{\footnotesize extracting data for\\\footnotesize each attributes};
\draw[->,thick](F)--(I)node[right,midway]{\footnotesize normalize};
\draw[->,thick](G)--(J)node[right,midway]{\footnotesize normalize};
\draw[->,thick](H)--(K)node[right,midway]{\footnotesize normalize};
\draw[->,thick](K)--(L)node[right,pos=0.75]{\footnotesize weighting method};
\draw[->,thick](M)--(N)node[right,midway]{\footnotesize perform RNNA $\forall v_i\in\Lambda$};
\draw[->,thick](N)--(O)node[right,midway]{\footnotesize perform 2-opt};
\draw[->,thick,dashed](O)--(P)node[right,midway]{\footnotesize repeat using different $\mathbf{w}$};
\end{tikzpicture}
\caption{Solution Scheme 1}
\end{figure}
\end{document}
答案1
您可以scope
在背景层上添加一个,然后定义一个相对于的节点current bounding box.west
。然后,您可以绘制线条并在相对于此新节点的位置添加标签,以使所有内容保持正确对齐。
编辑:正如评论中指出的那样,最好使用\tikzset
而不是\tikzstyle
。您还可以在 选项中定义样式tikzpicture
,如下所示。此外,您可以通过创建基本样式(例如 )来简化代码,然后根据基本样式myrect
定义其他样式(rectshort
、rectmed
和)。rectlong
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,decorations.pathreplacing, positioning, shapes.geometric}
\begin{document}
\pagestyle{empty}
\begin{figure}
\centering
\begin{tikzpicture}[myrect/.style = {draw,rectangle,rounded corners,fill=white!20,text centered,minimum height=1.75em},
rectshort/.style = {myrect,text width=5em},
rectmed/.style = {myrect,text width=10em},
rectlong/.style = {myrect,text width=15em},
]
\node[rectmed](A){\small User input};
\node[rectmed,below left=0.75cm and 1.2cm of A](B){\small terrain map};
\node[rectmed,below=0.5cm of B](E){\small vertex-weighted grid graph $G$};
\node[rectshort,below=1.5cm of E](G){\small $c^2=\left[\ldots\right]$};
\node[rectshort,left=0.5cm of G](F){\small $c^1=\left[\ldots\right]$};
\node[rectshort,right=0.5cm of G](H){\small $c^3=\left[\ldots\right]$};
\node[rectshort,below=0.5cm of G](J){\small $\hat{c}^2=\left[\ldots\right]$};
\node[rectshort,left=0.5cm of J](I){\small $\hat{c}^1=\left[\ldots\right]$};
\node[rectshort,right=0.5cm of J](K){\small $\hat{c}^3=\left[\ldots\right]$};
\node[rectshort,right=0.5cm of K](C){\small $\mathbf{w}=(w_1,w_2,w_3)$};
\node[rectmed,below=1.2cm of K](L){\small grid graph with weighted sum cost $G'$};
\node[rectshort,right =2.5cm of L](D){\small $\Lambda=\langle v_s,\ldots,v_t\rangle$};
\node[rectlong,below =10cm of A](M){\small Complete graph $K_{n+2}$};
\node[rectlong,below =1cm of M](N){\small Best complete graph $\pi_{st}^*$};
\node[rectlong,below =1cm of N](O){\small Improved best $\pi_{st}^*$};
\node[rectlong,below =1cm of O](P){\small List of Pareto Optimal $\pi_{st}^*$ corresponds to different $\mathbf{w}$};
\node[draw, diamond,aspect=4.5,below=0.5cm of P,align=center](Q){\small User provide limit\\\small constraints?};
\node[rectshort,below left=0.5cm and 1.5cm of Q](R){\small $\varepsilon$-constraint method};
\node[rectshort,below right=0.5cm and 1.5cm of Q](S){\small Ideal point method};
\node[rectmed,below=1.5cm of Q](T){\small Final solution for user};
%simple arrow
\foreach \x/\y in {A/C, B/E, P/Q} \draw[->,thick](\x)--(\y);
%bended arrow
\foreach \from/\height/\to in {A.south/-4/B.north, A.south/-4/D.north, E.south/-12/F.north, E.south/-12/H.north, C.south/-4/L.north, I.south/-5.3/L.north, J.south/-5.3/L.north, D.south/-4/M.north, R.south/-2/T.north, S.south/-2/T.north}
\draw[->,thick](\from) |- ++(0,\height mm) -| (\to);
%bended labelled arrow
\draw[->,thick] (L.south) |- ++(0,-4.1mm) -| (M.north) node[right,pos=0.75,align=left] {\footnotesize perform Dijkstra's or A* \\\footnotesize algorithm $\forall v_i,v_j\in\Lambda$};
\draw[->,thick] (Q.west) |- ++(0,0mm) -| (R.north) node[above, pos=0.25] {\footnotesize yes};
\draw[->,thick] (Q.east) |- ++(0,0mm) -| (S.north) node[above, pos=0.25] {\footnotesize no};
%labelled arrow
\draw[->,thick](E)--(G)node[right,pos=0.35,align=left]{\footnotesize extracting data for\\\footnotesize each attributes};
\draw[->,thick](F)--(I)node[right,midway]{\footnotesize normalize};
\draw[->,thick](G)--(J)node[right,midway]{\footnotesize normalize};
\draw[->,thick](H)--(K)node[right,midway]{\footnotesize normalize};
\draw[->,thick](K)--(L)node[right,pos=0.75]{\footnotesize weighting method};
\draw[->,thick](M)--(N)node[right,midway]{\footnotesize perform RNNA $\forall v_i\in\Lambda$};
\draw[->,thick](N)--(O)node(NO)[right,midway]{\footnotesize perform 2-opt};
\draw[->,thick,dashed](O)--(P)node(OP)[right,midway]{\footnotesize repeat using different $\mathbf{w}$};
%% for phases
\begin{scope}[on background layer]
\node(pre) at (current bounding box.west |- L)[left=1cm]{};
\draw[red](pre |- L) -- (current bounding box.east |- L);
\draw[red](pre |- OP.north) -- (current bounding box.east |- OP.north) node(search)[at start]{};
\node at ($(pre)!0.5!(current bounding box.north west)$)[rotate=90,anchor=north]{Preprocessing};
\node at ($(pre)!0.5!(search)$)[rotate=90,anchor=north]{Path Searching};
\node at ($(search)!0.5!(current bounding box.south west)$)[rotate=90,anchor=north,align=center]{Postprocessing\\Decision Making};
\draw[red,decorate,decoration=brace](I |- NO) -- (I |- pre.south)node[midway,above,sloped]{A};
\draw[red,decorate,decoration=brace](I |- OP.north)--(I |- NO.south)node[midway,above,sloped]{B};
\end{scope}
\end{tikzpicture}
\caption{Solution Scheme 1}
\end{figure}
\end{document}