检测问题

检测问题

我想知道是什么原因导致以下图像如此严重地偏离中心,以及我该如何解决这个问题(请注意左上角的巨大空间)。目前我只是在对 .pdf 进行后期处理。代码和生成的图像附在下面

    \documentclass{standalone}

    \usepackage[latin1]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \begin{document}

    % Define block styles
    \tikzstyle{decision} = [diamond, draw, fill=none, 
        text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=none, 
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{butt} = [draw, ellipse,fill=none, node distance=3cm,
        minimum height=2em]

    \begin{tikzpicture}[node distance = 2cm, auto]

        % Place node
        \node [] (init) {};
        \node [right of=init, node distance=5cm] (system) {};
        \node [decision, below of=system, node distance=6cm] (triangle) {}; 
        \node [below of=init] (identify) {};
        \node [below of=identify] (evaluate) {};
        \node [left of=evaluate, node distance=5cm] (update) {};
        \node [block, below of=evaluate, node distance=5cm] (monitor) {Monitor Mode};
        \node [below of=monitor, node distance=5cm] (stop) {};
        \node [block, right of=monitor, node distance=8cm] (command) {Command Mode};
        \node [left of=monitor, node distance=3cm] (x) {};
        \node [below of=triangle, node distance=5.5cm] (nothing) {FRISTOP};
        \node [right of=monitor, below of=monitor, node distance=0.6cm] (a) {};
        \node [right of=monitor, above of=monitor, node distance=0.6cm] (b) {};
        % Draw edges     
        \path [line] (evaluate) -- node [near start]{FRIOPEN}(monitor);      
        \path [line] (monitor) -- node [near end]{FRICLOSE}(stop); 
        \path [line] (triangle) -| node [near start, black]{Timing In Sync}(command);
(monitor);
        \path [line] (x) -- node {Command}(monitor);
        \path [line] (x) -- node [below]{Error}(monitor);
        \draw [->] (command.south) |- ++(0,-2) -| (a);
        \path [line] (triangle) |- node [near end]{Quality Not Sufficient}(monitor);
        \path [line] (b) |- node [near start, right, black]{FRISTART}(triangle);
    \end{tikzpicture}


    \end{document}

在此处输入图片描述

答案1

检测问题

通过\frame在 周围添加tikzpicture,您将在图像周围获得一个紧密的框架,它将向您显示实际发生的情况以及额外空间的位置;在 上添加小边框standalone也有帮助:

    \documentclass[border=3pt]{standalone}

    \usepackage[latin1]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}
    \begin{document}

    % Define block styles
    \tikzstyle{decision} = [diamond, draw, fill=none, 
        text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=none, 
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{butt} = [draw, ellipse,fill=none, node distance=3cm,
        minimum height=2em]

    \frame{\begin{tikzpicture}[node distance = 2cm, auto]

        % Place node
        \node [] (init) {};
        \node [right of=init, node distance=5cm] (system) {};
        \node [decision, below of=system, node distance=6cm] (triangle) {}; 
        \node [below of=init] (identify) {};
        \node [below of=identify] (evaluate) {};
        \node [left of=evaluate, node distance=5cm] (update) {};
        \node [block, below of=evaluate, node distance=5cm] (monitor) {Monitor Mode};
        \node [below of=monitor, node distance=5cm] (stop) {};
        \node [block, right of=monitor, node distance=8cm] (command) {Command Mode};
        \node [left of=monitor, node distance=3cm] (x) {};
        \node [below of=triangle, node distance=5.5cm] (nothing) {FRISTOP};
        \node [right of=monitor, below of=monitor, node distance=0.6cm] (a) {};
        \node [right of=monitor, above of=monitor, node distance=0.6cm] (b) {};
        % Draw edges     
        \path [line] (evaluate) -- node [near start]{FRIOPEN}(monitor);      
        \path [line] (monitor) -- node [near end]{FRICLOSE}(stop); 
        \path [line] (triangle) -| node [near start, black]{Timing In Sync}(command);
(monitor);
        \path [line] (x) -- node {Command}(monitor);
        \path [line] (x) -- node [below]{Error}(monitor);
        \draw [->] (command.south) |- ++(0,-2) -| (a);
        \path [line] (triangle) |- node [near end]{Quality Not Sufficient}(monitor);
        \path [line] (b) |- node [near start, right, black]{FRISTART}(triangle);
    \end{tikzpicture}}


    \end{document}

这将产生

在此处输入图片描述

该图显示了两个主要问题:

  1. 有些事外部tikzpicture图像向右移动。
  2. 图像内部有一些东西将元素向下和向右推。

寻找罪魁祸首

  1. 唯一可能产生上述 1. 的元素是\tikzstyles

  2. 在空节点中放置一些标签来查看实际发生的情况:

代码:

\documentclass[border=3pt]{standalone}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\begin{document}

% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=none, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=none, 
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{butt} = [draw, ellipse,fill=none, node distance=3cm,
    minimum height=2em]

\frame{\begin{tikzpicture}[node distance = 2cm, auto]

    % Place node
    \node [] (init) {Init};
    \node [right of=init, node distance=5cm] (system) {System};
    \node [decision, below of=system, node distance=6cm] (triangle) {}; 
    \node [below of=init] (identify) {Identify};
    \node [below of=identify] (evaluate) {Evaluate};
    \node [left of=evaluate, node distance=5cm] (update) {Update};
    \node [block, below of=evaluate, node distance=5cm] (monitor) {Monitor Mode};
    \node [below of=monitor, node distance=5cm] (stop) {};
    \node [block, right of=monitor, node distance=8cm] (command) {Command Mode};
    \node [left of=monitor, node distance=3cm] (x) {};
    \node [below of=triangle, node distance=5.5cm] (nothing) {FRISTOP};
    \node [right of=monitor, below of=monitor, node distance=0.6cm] (a) {};
    \node [right of=monitor, above of=monitor, node distance=0.6cm] (b) {};
    % Draw edges     
    \path [line] (evaluate) -- node [near start]{FRIOPEN}(monitor);      
    \path [line] (monitor) -- node [near end]{FRICLOSE}(stop); 
    \path [line] (triangle) -| node [near start, black]{Timing In Sync}(command);
(monitor);
    \path [line] (x) -- node {Command}(monitor);
    \path [line] (x) -- node [below]{Error}(monitor);
    \draw [->] (command.south) |- ++(0,-2) -| (a);
    \path [line] (triangle) |- node [near end]{Quality Not Sufficient}(monitor);
    \path [line] (b) |- node [near start, right, black]{FRISTART}(triangle);
\end{tikzpicture}}


\end{document}

新结果:

在此处输入图片描述

可能的解决方案

正如前面的分析显示,您的代码有两个主要问题:

  • 您正在使用一些没有内容的节点将图像向下和向右推;这些节点不是真正需要的,因此您可以抑制它们(参见下面的代码)。

  • \tikzstyles在文档正文中将图像推到右侧。将它们移动到序言部分(并将它们更改为\tikzset;参见下面的代码)。

修改后的代码中包含了以下附加建议:

  • 不要使用旧的、有问题的of=语法,而要使用库=of中的语法positioning

  • 不要使用旧的\tikstyle,而要使用\tikzset

  • 您的代码可以简化。

新代码:

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

% Define block styles
\tikzset{
  decision/.style={
    diamond, 
    draw, 
    text width=4.5em, 
    align=center,
    inner sep=0pt
    },
  block/.style={
    rectangle, 
    draw,
    text width=5em, 
    align=center, 
    rounded corners, 
    minimum height=4em
    },
  line/.style={draw, -latex'},
  butt/.style={
    draw, 
    ellipse,
    node distance=3cm,
  minimum height=2em
  }
}

\begin{document}

\begin{tikzpicture}[auto]
% Place node
\node[block] 
  (monitor) {Monitor Mode};
\node[block, right=5.5cm of monitor] 
  (command) {Command Mode};
\node[decision,above right=1cm and 3.5cm of monitor] 
  (tim) {};

% Draw edges 
\path[line] 
  (tim) -| 
    node[pos=0.4] {Timing in Sync}
  (command);  
\path[line] 
  (monitor) -- 
    node[near end] {FRICLOSE} 
  ++(0,-4cm); 
\path[line,<-] 
  (monitor) -- 
    node[near end,swap] {FRIOPEN} 
  ++(0,4cm); 
\path [line] 
  (monitor.60) |- 
    node[pos=0.4,swap] {FRISTART} 
  (tim); 
\path[line] 
  (tim) |- 
    node[near end] {Quality Not Sufficient} 
  (monitor); 
\path[line] 
  (command) |-
  ++(0,-2cm) -| 
    node[near start,swap] {FRISTOP} 
  (monitor.300); 
\path[line] 
  ([xshift=-2cm]monitor.west) --
    node {Command} 
    node[swap] {error} 
  (monitor); 
\end{tikzpicture}

\end{document}

结果:

在此处输入图片描述

答案2

您有两个幻影节点将图片推开:

在此处输入图片描述

\documentclass{standalone}

    \usepackage[latin1]{inputenc}
    \usepackage{tikz}
    \usetikzlibrary{shapes,arrows}

    % Define block styles
    \tikzstyle{decision} = [diamond, draw, fill=none, 
        text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
    \tikzstyle{block} = [rectangle, draw, fill=none, 
        text width=5em, text centered, rounded corners, minimum height=4em]
    \tikzstyle{line} = [draw, -latex']
    \tikzstyle{butt} = [draw, ellipse,fill=none, node distance=3cm,
        minimum height=2em]

    \begin{document}
    \begin{tikzpicture}[node distance = 2cm, auto]

         Place node
        \node [] (init) {x};
        \node [right of=init, node distance=5cm] (system) {};
        \node [decision, below of=system, node distance=6cm] (triangle) {}; 
        \node [below of=init] (identify) {};
        \node [below of=identify] (evaluate) {};
        \node [left of=evaluate, node distance=5cm] (update) {y};
        \node [block, below of=evaluate, node distance=5cm] (monitor) {Monitor Mode};
        \node [below of=monitor, node distance=5cm] (stop) {};
        \node [block, right of=monitor, node distance=8cm] (command) {Command Mode};
        \node [left of=monitor, node distance=3cm] (x) {};
        \node [below of=triangle, node distance=5.5cm] (nothing) {FRISTOP};
        \node [right of=monitor, below of=monitor, node distance=0.6cm] (a) {};
        \node [right of=monitor, above of=monitor, node distance=0.6cm] (b) {};
%         Draw edges     
        \path [line] (evaluate) -- node [near start]{FRIOPEN}(monitor);      
        \path [line] (monitor) -- node [near end]{FRICLOSE}(stop); 
        \path [line] (triangle) -| node [near start, black]{Timing In Sync}(command);
(monitor);
        \path [line] (x) -- node {Command}(monitor);
        \path [line] (x) -- node [below]{Error}(monitor);
        \draw [->] (command.south) |- ++(0,-2) -| (a);
        \path [line] (triangle) |- node [near end]{Quality Not Sufficient}(monitor);
        \path [line] (b) |- node [near start, right, black]{FRISTART}(triangle);
    \end{tikzpicture}


    \end{document}

相关内容