笔记:

笔记:
\documentclass{article}

%\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows} % For flowchart and Diagram

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value
%%%>

\begin{document}
\pagestyle{empty}

Text here

% Define block styles
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2.5cm,minimum height=2em]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110,minimum height=2em,text centered, draw=black, fill=blue!30]
\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=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{line} = [draw, -latex']  
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [io] (init) {Initialize};
    \node [cloud, above of=init] (Start) {Start};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {Process};
    \node [block, below of=identify] (evaluate) {Evaluate};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {Decision};
    \node [cloud, below of=decide, node distance=3cm] (Stop) {Stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(Stop);
    \path [line,dashed] (Start) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}


\end{document}

这给出

在此处输入图片描述

我想绘制带有说明的图表。但这只会生成忽略同一文档中其他文本的图表。我该怎么做?

答案1

如果我理解正确的话,你可能需要删除这些行

\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value

这些行旨在生成紧凑的图片,不能用于常规文档。如果没有这些行,您的代码将:

\documentclass{article}
\usepackage{lipsum}
%\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows} % For flowchart and Diagram

%%%<
\usepackage{verbatim}
%\usepackage[active,tightpage]{preview}  % For flowchart and Diagram
%\PreviewEnvironment{tikzpicture}  % For flowchart and Diagram
%\setlength\PreviewBorder{60pt}% to control size of the diagram, to reduce increase +ve value
%%%%>

\begin{document}
\pagestyle{empty}

Text here

% Define block styles
\tikzstyle{cloud} = [draw, ellipse,fill=red!20, node distance=2.5cm,minimum height=2em]
\tikzstyle{io} = [trapezium, trapezium left angle=70, trapezium right angle=110,minimum height=2em,text centered, draw=black, fill=blue!30]
\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=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{line} = [draw, -latex']
\begin{tikzpicture}[node distance = 2cm, auto]
    % Place nodes
    \node [io] (init) {Initialize};
    \node [cloud, above of=init] (Start) {Start};
    \node [cloud, right of=init] (system) {system};
    \node [block, below of=init] (identify) {Process};
    \node [block, below of=identify] (evaluate) {Evaluate};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {Decision};
    \node [cloud, below of=decide, node distance=3cm] (Stop) {Stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- (evaluate);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(Stop);
    \path [line,dashed] (Start) -- (init);
    \path [line,dashed] (system) -- (init);
    \path [line,dashed] (system) |- (evaluate);
\end{tikzpicture}
\lipsum

\end{document}

在此处输入图片描述

笔记:

  1. 代替\tikzset\tikzstyle被弃用的。
  2. 使用positioning库并使用below=of,right = of语法以获得更好的放置(而不是below of=)。

相关内容