编辑

编辑

我正在尝试在 LaTeX 中绘制一个图表,但有一个问题,就是我需要制作多条线才能到达特定的输出(结果),但它们却进行嵌套输出。

看看我的图表

在此处输入图片描述

我写的代码是这样的:

\documentclass[conference]{IEEEtran}
\usepackage{tikz}
\usetikzlibrary{shapes, shadows, arrows}
\ifCLASSINFOpdf
\hyphenation{op-tical net-works semi-conduc-tor}



\begin{document}


\newpage

\tikzstyle{decision} = [diamond, draw, fill=blue!50, text width=8em, text centered, minimum height=15mm, node distance=5em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{elli} = [draw, ellipse, fill=red!50, text width=8em, text centered, minimum height=15mm, node distance=5em]
\tikzstyle{block} = [draw, rectangle, fill=blue!50, text width=10em, text centered, minimum height=10mm, node distance=5em]
\begin{tikzpicture}
\node[block] (start) {1, 2};
\node[decision, below of=start, yshift=-5em](dec1) {...?};
\node[decision, below of=dec1, yshift=-8em](dec2) { 'Yes'?};
\node[decision, right of=dec2, xshift= 8em](dec3) { 'No'?};
\node[elli, below of=dec3, yshift=-5em, yshift=-1em](look) {look};
\node[decision, below of=look, yshift= -5em](dec4) {found?};
\node[elli, right of=dec4, xshift=10em](AddToYes) {Add to 'Yes'};
\node[elli, left of=dec4, xshift=-10em](AddToNo) {Add to 'No'};
\node[block, below of= AddToYes, yshift=-5em](Res) {Result};
%arrows
\path [line] (start) -- (dec1);
\path [line] (dec1) -- (dec2);
\path [line] (dec2) -- (dec3);
\path [line] (dec3) -- (look);
\path [line] (look) -- (dec4);
\path [line] (dec4) -- (AddToNo);
\path [line] (dec4) -- (AddToYes);
\path [line] (AddToYes) -- (Res);
\path [line] (AddToNo) |- (Res);
\path [line] (dec3) |- (Res);
\path [line] (dec2) |- (Res);
\path [line] (dec1) -| node[yshift=0.5em, xshift=-17em]{No} (Res);



\end{tikzpicture}


\end{document}

答案1

我会使用类似chains库的东西或节点矩阵或两者。不过,我并不完全确定图表应该是什么样子。

像这样的事情??

链式流动

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{shapes.geometric, shadows, arrows, chains, scopes, positioning}
\hyphenation{op-tical net-works semi-conduc-tor}
\begin{document}
\tikzset{
  decision/.style = {diamond, draw, fill=blue!50, text width=8em, text centered, minimum height=15mm},
  line/.style = {draw, -latex'},
  elli/.style = {draw, ellipse, fill=red!50, text width=8em, text centered, minimum height=15mm},
  block/.style = {draw, rectangle, fill=blue!50, text width=10em, text centered, minimum height=10mm},
}
\begin{tikzpicture}[start chain=first going below, node distance=5em, every join/.style={line}]
  \node [on chain, block] (start) {1, 2};
  \node [on chain, decision, join] (dec1) {...?};
  {[start branch=helper going left]
    \node [on chain, shape=coordinate] (helper) {};
  }
  \node [on chain, decision, join] (dec2) { 'Yes'?};
  {[start branch=no going right]
    \node [on chain, decision, join] (dec3) { 'No'?};
    {[continue chain=going below]
      \node [on chain, elli, join] (look) {look};
      \node [on chain, decision, join] (dec4)  {found?};
      {[start branch=add to no going right]
        \node [on chain, elli, join] (AddToYes) {Add to 'Yes'};
      }
      \node [on chain, elli, join] (AddToNo) {Add to 'No'};
    }
  }
  \node [on chain, below=of dec2 |- AddToNo, block, join] (res) {Result};
  \draw [line] (AddToNo) |- (res);
  \draw [line] (dec1) -- (helper) |- (res);
  \draw [line] (AddToYes) |- (res);
  \draw [line] (dec1) -| (AddToYes);
\end{tikzpicture}
\end{document}

编辑

另一种可能性是,正如我提到的,使用该matrix库。例如,以下内容基于您的扫描图(因此没有elli类型节点,但您可以轻松调整):

矩阵选项

\documentclass[tikz,border=10pt,multi]{standalone}
\usetikzlibrary{shapes.geometric, arrows, matrix, quotes}
\begin{document}
\tikzset{
  decision/.style = {diamond, draw, fill=blue!50, text width=8em, text centered, minimum height=15mm},
  line/.style = {draw, -latex'},
  block/.style = {draw, rectangle, fill=blue!50, text width=10em, text centered, minimum height=10mm},
}
\begin{tikzpicture}[every edge quotes/.append style={midway, auto}]
  \matrix [matrix of nodes, column sep=5em, row sep=5em]
  {
    |(start) [block]| 1, 2 & & \\
    |(dec1) [decision]| \dots? & & \\
    |(yes) [decision]| `Yes' & & \\
    |(no) [decision]| `No' & & |(look) [block]| Look\dots \\
    & |(add2no) [block]| Add to `No' & |[decision] (found)| Found? \\
    & & |(add2yes) [block]| Add to `Yes' \\
    |(res) [block]| Result & & \\
  };
  \foreach \i/\j/\k in {start/dec1/,dec1/yes/Yes,yes/no/No,no/look/No,no/res/Yes,found/add2no/No,found/add2yes/Yes,look/found/} \draw [line] (\i) edge ["\k"] (\j);
  \draw [line] (dec1.west) -- +(-5em,0) node [midway, above] {No}  |- (res);
  \draw [line] (add2yes) |- (res);
  \draw [line] (add2no) |- (res);
  \draw [line] (yes.west) -- +(-2.5em,0) node [midway, above] {Yes} |- (res);
\end{tikzpicture}
\end{document}

相关内容