6

I'm wondering what is causing the following image to be so horribly off centred and how I might fix this issue (Note the massive space in the top left corner). Currently I am just post processing the .pdf. Code and resulting image are attached below

    \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}

enter image description here

14

Detecting the problem

By adding a \frame around the tikzpicture, you'll get a tight frame around the image that will show you what is really happening and where is the additional space; adding a little border to the standalone also helps:

    \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}

This will produce

enter image description here

The image shows two main problems:

  1. There is something outside the tikzpicture that is moving the image to the right.
  2. There's something inside the image that is pushing the elements downwards and to the right.

Finding the culprits

  1. The only elements that might produce 1. above are the \tikzstyles.

  2. Place some labels in the empty nodes to see what is realy going on:

The code:

\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}

The new result:

enter image description here

A possible solution

As the previous analysys shows, there are two main problems with your code:

  • You are using some nodes with no content that push the image downwards and to the right; those nodes are not really needed, so you can suppress them (see code below).

  • Your \tikzstyles in the body of the document push the image to the right. Move them to the preamble (and change them to \tikzset; see code below).

Additional recommendations incorporated in the modified code below:

  • Instead of the old, problematic, of= syntax, use the =of syntax from the positioning library.

  • Instead of the old \tikstyle, use \tikzset.

  • Your code can be simplified.

The new code:

\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}

The result:

enter image description here

4

You have two phantom nodes that push the picture off :

enter image description here

\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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.