使用 tikz 引导元素之间的线条时遇到问题

使用 tikz 引导元素之间的线条时遇到问题

在下面的代码中,我想从最后一个菱形到最上面的菱形画一条线,如下面的 ascii-art 所示

                     /\ 
                |---/  \
        /\      |   \  /
       /  \     |    \/
       \  /------
        \/

你能告诉我如何实现上述排列吗?另外,我该如何水平circle2对齐setloadavg

使用我当前的代码,垂直线相互重叠。我从 tex 代码输出的内容如下: 在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage{fixltx2e}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{document}
\pagestyle{empty}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=blue!20, 
    text width=10em, text centered, rounded corners, minimum height=4em]
\tikzstyle{mycircle} = [circle, thick, draw=orange, minimum height=4mm]

\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=3cm,
    minimum height=2em]

\begin{tikzpicture}[align=center,node distance = 2cm, auto]
    % Place nodes
    \node [block] (init) {Read system data};
    \node [mycircle, below left of=init, node distance=4cm] (circle2) {2};
    \node [block, below of=init, node distance=2cm] (setloadavg) {Set average loading level to L\textsubscript{avg}=[0.8,0.9,1,1.1]};
    \node [decision, right of=setloadavg, node distance=8cm] (final) {Is K=N(no. of runs)?};
    \node [mycircle, right of=final, node distance=3cm] (circle5) {2};
    \node [mycircle, below of=final, node distance=3cm] (circle6) {1};
    \node [block, below of=setloadavg, node distance=2cm] (startsim) {Start simulation (run 1) to generate cascade data, K=0};
    \node [block, below of=startsim, node distance=2cm] (setloadlevel) {Set Loading level=L\textsubscript{avg} where varies between +0.5 to -0.5, K=K+1};
    \node [block, below of=setloadlevel, node distance=2cm] (runloadflow) {Remove line randomly and run load flow};
    \node [block, below of=runloadflow, node distance=2cm] (checkoverload) {Check for line overloads};

    \node [decision, below of=checkoverload, node distance=3cm] (decision1) {Is any line overloaded?};
    \node [mycircle, right of=decision1, node distance=3cm] (circle3) {1};
    \node [block, below of=decision1, node distance=3cm] (trip) {Trip the line and note the instant time of trip};
    \node [decision, below of=trip] (reachedsat) {Reached saturation?};
    \node [mycircle, below of=reachedsat, node distance=2cm] (circle4) {1};


    % Draw edges
    \path [line] (init) -- (setloadavg);
    \path [line] (circle2) -- (setloadavg);
    \path [line] (setloadavg) -- (startsim);
    \path [line] (startsim) -- (setloadlevel);
    \path [line] (setloadlevel) -- (runloadflow);
    \path [line] (runloadflow) -- (checkoverload);
    \path [line] (checkoverload) -- (decision1);

    \path [line] (decision1) -- node [near start] {No} (circle3);
    \path [line] (decision1) -- node [near start] {Yes} (trip);

    \path [line] (trip) -- (reachedsat);
    \path [line] (reachedsat) -- node [near start] {No} (circle4);
    \path [line] (reachedsat) -| node [near start] {Yes} (final);

    \path [line] (final) -- node [near start] {No} (circle5);
    \path [line] (final) -- node [near start] {Yes} (circle6);


\end{tikzpicture}
\end{document}

谢谢

答案1

\path [line] (reachedsat) -- node [near start] {Yes} ++(5,0) |-  (final);

这是您清理后的代码:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{positioning}
\usepackage{fixltx2e}

\begin{document}
\pagestyle{empty}

% Define block styles
\tikzset{decision/.style = {diamond, draw, fill=blue!20,
         text width=4.5em, text badly centered,  inner sep=0pt},
    block/.style = {rectangle, draw, fill=blue!20,
         text width=10em, text centered, rounded corners, minimum height=4em},
    mycircle/.style = {circle, thick, draw=orange, minimum height=4mm},
    line/.style = {draw, -latex'},
    cloud/.style = {draw, ellipse,fill=red!20, minimum height=2em}
}

\begin{tikzpicture}[align=center, auto]
    % Place nodes
    \node [block] (init) {Read system data};
    \node [block, below = of init] (setloadavg) {Set average loading level to L\textsubscript{avg}=[0.8,0.9,1,1.1]};
    \node [mycircle, left = of setloadavg] (circle2) {2};
    \node [decision, right = 4cm of setloadavg, ] (final) {Is K=N(no. of runs)?};
    \node [mycircle, right =of final, ] (circle5) {2};
    \node [mycircle, below = of final, ] (circle6) {1};
    \node [block, below = of setloadavg, ] (startsim) {Start simulation (run 1) to generate cascade data, K=0};
    \node [block, below = of startsim, ] (setloadlevel) {Set Loading level=L\textsubscript{avg} where varies between +0.5 to -0.5, K=K+1};
    \node [block, below =of setloadlevel, ] (runloadflow) {Remove line randomly and run load flow};
    \node [block, below =of runloadflow, ] (checkoverload) {Check for line overloads};

    \node [decision, below = of checkoverload, ] (decision1) {Is any line overloaded?};
    \node [mycircle, right = of decision1, ] (circle3) {1};
    \node [block, below = of decision1,] (trip) {Trip the line and note the instant time of trip};
    \node [decision, below =of trip] (reachedsat) {Reached saturation?};
    \node [mycircle, below = of reachedsat, ] (circle4) {1};


    % Draw edges
    \path [line] (init) -- (setloadavg);
    \path [line] (circle2) -- (setloadavg);
    \path [line] (setloadavg) -- (startsim);
    \path [line] (startsim) -- (setloadlevel);
    \path [line] (setloadlevel) -- (runloadflow);
    \path [line] (runloadflow) -- (checkoverload);
    \path [line] (checkoverload) -- (decision1);

    \path [line] (decision1) -- node [near start] {No} (circle3);
    \path [line] (decision1) -- node [near start] {Yes} (trip);

    \path [line] (trip) -- (reachedsat);
    \path [line] (reachedsat) -- node [near start] {No} (circle4);
    \path [line] (reachedsat) -- node [near start] {Yes} ++(4,0) |-  (final);

    \path [line] (final) -- node [near start] {No} (circle5);
    \path [line] (final) -- node [near start] {Yes} (circle6);


\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容