绘制流程图

绘制流程图

我想在乳胶中绘制一个流程图,主要思想就在这个图像中

在此处输入图片描述

我尝试这样做

在此处输入图片描述

通过使用此代码

\documentclass[12pt]{report} 

\usepackage{tikz}
 \usetikzlibrary{shapes.geometric, arrows,positioning}

  \tikzstyle{startstop} = [rectangle, text width=3cm, minimum   height=1cm,text centered, draw=black, fill=red!30]
   \tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right 
   angle=110, text width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
   \tikzstyle{process} = [rectangle, text width=3cm, minimum height=1cm,    text centered, draw=black, fill=orange!30]
   \tikzstyle{decision} = [diamond, text width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
   \tikzstyle{arrow} = [thick,->,>=stealth]



\begin{document}


\begin{tikzpicture}[node distance=0.8cm,font=\sf]

   \node (in1) [startstop] {\textbf{Input}: Original sample $X$};
   \node (pro1) [process, below=of in1] {pre-test for normality};
   \node (dec1) [decision, below=of pro1,xshift=5cm] {$H_0^{(1)}$ is not rejected (Normal)};
   \node (dec2) [decision, below=of pro1,xshift=-5cm] {$H_0^{(1)}$ is rejected (Not normal)};
\node (pro2) [process, below=of dec1] {Apply t-test};
\node (pro3) [process, below=of dec2] {Apply Wilcoxon test};
\node (dec3) [decision, below=of pro2,xshift=2.25cm] {$H_0^{(2t)}$ is not rejected};
\node (dec4) [decision, below=of pro2,xshift=-2.25cm] {$H_0^{(2t)}$ is rejected };
\node (dec5) [decision, below=of pro3,xshift=2.25cm] {$H_0^{(2W)}$ is not rejected};
\node (dec6) [decision, below=of pro3,xshift=-2.25cm] {$H_0^{(2W)}$ is rejected };
 \node (in2) [startstop, right=of in1]{ Bootstrap sample };

  \draw [arrow] (in1) -- (pro1);
   \draw [arrow] (pro1) -- (dec1);
   \draw [arrow] (pro1) -- (dec2);
 \draw [arrow] (dec1) -- (pro2);
 \draw [arrow] (dec2) -- (pro3);
\draw [arrow] (pro2) -- (dec3);
   \draw [arrow] (pro2) -- (dec4);
   \draw [arrow] (pro3) -- (dec5);
   \draw [arrow] (pro3) -- (dec6);
\draw [arrow,dashed]   (in1)-- node[anchor=south] {Draw} (in2) ;
\draw [arrow,dashed] (in2) |- (pro1);


  \end{tikzpicture}


\end{document}

这种方法正确吗?我该如何改进这段代码?

答案1

我可以按照您提供的代码运行,但图形不适合页面。似乎如果不以​​某种方式缩放它,它就太宽了。您可以考虑使用更改页面包装及其调整宽度宏暂时缩小边距,并且中心环境以使图形在新加宽的边距内居中。我没有仔细检查代码生成的流程图是否准确反映了您手动提供的流程图,但我相信您可以做到这一点。

以下是我修改后的代码:

\documentclass[12pt]{report} 
\usepackage{changepage}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, arrows,positioning}

\tikzstyle{startstop} = [rectangle, text width=3cm, minimum   height=1cm,text centered, draw=black, fill=red!30]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right 
angle=110, text width=3cm, minimum height=1cm, text centered, draw=black, fill=blue!30]
\tikzstyle{process} = [rectangle, text width=3cm, minimum height=1cm,    text centered, draw=black, fill=orange!30]
\tikzstyle{decision} = [diamond, text width=3cm, minimum height=1cm, text centered, draw=black, fill=green!30]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{document}
\begin{adjustwidth}{-2.5cm}{-2.5cm}
  \begin{center}
    \begin{tikzpicture}[node distance=0.8cm,font=\sf]
      \node (in1) [startstop] {\textbf{Input}: Original sample $X$};
      \node (pro1) [process, below=of in1] {pre-test for normality};
      \node (dec1) [decision, below=of pro1,xshift=5cm] {$H_0^{(1)}$ is not rejected (Normal)};
      \node (dec2) [decision, below=of pro1,xshift=-5cm] {$H_0^{(1)}$ is rejected (Not normal)};
      \node (pro2) [process, below=of dec1] {Apply t-test};
      \node (pro3) [process, below=of dec2] {Apply Wilcoxon test};
      \node (dec3) [decision, below=of pro2,xshift=2.25cm] {$H_0^{(2t)}$ is not rejected};
      \node (dec4) [decision, below=of pro2,xshift=-2.25cm] {$H_0^{(2t)}$ is rejected };
      \node (dec5) [decision, below=of pro3,xshift=2.25cm] {$H_0^{(2W)}$ is not rejected};
      \node (dec6) [decision, below=of pro3,xshift=-2.25cm] {$H_0^{(2W)}$ is rejected };
      \node (in2) [startstop, right=of in1]{ Bootstrap sample };
      
      \draw [arrow] (in1) -- (pro1);
      \draw [arrow] (pro1) -- (dec1);
      \draw [arrow] (pro1) -- (dec2);
      \draw [arrow] (dec1) -- (pro2);
      \draw [arrow] (dec2) -- (pro3);
      \draw [arrow] (pro2) -- (dec3);
      \draw [arrow] (pro2) -- (dec4);
      \draw [arrow] (pro3) -- (dec5);
      \draw [arrow] (pro3) -- (dec6);
      \draw [arrow,dashed]   (in1)-- node[anchor=south] {Draw} (in2) ;
      \draw [arrow,dashed] (in2) |- (pro1);
    \end{tikzpicture}
  \end{center}
\end{adjustwidth}
\end{document}

结果输出如下。标签顶部太宽,无法容纳箭头,因此移动Bootstrap 示例距离较远的节点会有所帮助。

在此处输入图片描述

另一种方法是使用独立文档类代替报告\includegraphics类。然后您可以使用图形包中包含生成的图形文件并将图形缩放到您认为合适的边距。

相关内容