13

This code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}

\tikzstyle{block} = [rectangle, draw, fill=blue!10, rounded corners, text centered,     text width = 7em, minimum height = 2em]
\tikzstyle{line} = [draw, -latex']

\begin{document}

\begin{tikzpicture}[]
% Place nodes
\node [block] (optimization) {Given \\optimization problem};
\node [block, right of=optimization, node distance=4cm]  (critical) {Find \\ critical points};
\node [block, right of = critical, node distance=4cm] (second) {Apply Second Derivatives Test to each critical point};
\node[block, below left=1cm and 1cm of second](case one) {$D(a, b) = 0$};
\node[block, below = 1cm of second](case two) {$D(a, b) >0$};
\node[block, below right = 1cm and 1cm of second](case three) {$D(a, b) < 0$};
\node[block, below = 1cm of case one](no info){No information about critical point $(a, b)$};
\node[block, below = 1cm of case two](saddle){$(a, b)$ is a saddle point};
\node[block, below = 1cm of case three](more){Check $f_{xx}(a, b)$};
\node[block, below left = 1cm and 0.1cm of more](a){$f_{xx}(a, b) > 0$};
\node[block, below right = 1cm and 0.1cm of more](b){$f_{xx}(a, b) < 0$};
\node[block, below = 1cm of a](min){$(a, b)$ is a local min};
\node[block, below = 1cm of b](max){$(a, b)$ is a local max};
% Draw edges
\path [line] (optimization) -- (critical);
\path [line] (critical) -- (second);
\path [line](second) -- (case one);
\path [line] (second) -- (case two);
\path [line] (second) -- (case three);
\path[line] (case one) -- (no info);
\path[line] (case two) -- (saddle);
\path[line] (case three) -- (more);
\path[line] (more) -- (a);
\path[line] (more) -- (b);
\path[line] (a) -- (min);
\path[line] (b) -- (max);
\end{tikzpicture}
\end{document}

has produce the flow chart:

flowchart

I am pretty happy with everything, except I would like the two nodes under "Check f_{xx}(a, b)" to be closer together. I thought I should be able to do this by doing something like:

\node[block, below left = 1cm and 0.1cm of more](a){$f_{xx}(a, b) > 0$}

and

\node[block, below right = 1cm and 0.1cm of more](b){$f_{xx}(a, b) < 0$}

but this did not work. Any suggestions?

17

You can be a little bit sneaky and use a negative value for the x-direction. Below I used below right = 1cm and -1cm of more. I also changed to \tikzset instead of \tikzstyle as the former is recommended, added the block style to all nodes, and used a loop to draw the arrows.

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows,shapes,positioning}
\usetikzlibrary{calc,decorations.markings}

\tikzset{
  block/.style={rectangle, draw, fill=blue!10, rounded corners, text centered,     text width = 7em, minimum height = 2em},
  line/.style={draw, -latex'}
  }

\begin{document}

\begin{tikzpicture}[every node/.style={block}]
% Place nodes
\node (optimization) {Given \\optimization problem};
\node [right of=optimization, node distance=4cm]  (critical) {Find \\ critical points};
\node [right of = critical, node distance=4cm] (second) {Apply Second Derivatives Test to each critical point};
\node[below left=1cm and 1cm of second](case one) {$D(a, b) = 0$};
\node[below = 1cm of second](case two) {$D(a, b) >0$};
\node[below right = 1cm and 1cm of second](case three) {$D(a, b) < 0$};
\node[below = 1cm of case one](no info){No information about critical point $(a, b)$};
\node[below = 1cm of case two](saddle){$(a, b)$ is a saddle point};
\node[below = 1cm of case three](more){Check $f_{xx}(a, b)$};
\node[below left = 1cm and -1cm of more](a){$f_{xx}(a, b) > 0$};
\node[below right = 1cm and -1cm of more](b){$f_{xx}(a, b) < 0$};
\node[below = 1cm of a](min){$(a, b)$ is a local min};
\node[below = 1cm of b](max){$(a, b)$ is a local max};
% Draw edges

\foreach \x/\y in {optimization/critical,
                   critical/second,
                   second/case one,
                   second/case two,
                   second/case three,
                   case one/no info,
                   case two/saddle,
                   case three/more,
                   more/a,
                   more/b,
                   a/min,
                   b/max}
   \draw [line] (\x) -- (\y);
\end{tikzpicture}
\end{document}

enter image description here

Second alternative

Another option would be to use the on grid option for those two nodes. With on grid, the node distance is calculated from the center of the nodes, instead of the border. Note that you need the place on grid before the below ..., i.e.

\node[on grid,below left = 1.5cm and 1.8cm of more](a){$f_{xx}(a, b) > 0$};
\node[on grid,below right = 1.5cm and 1.8cm of more](b){$f_{xx}(a, b) < 0$};

Complete code:

\documentclass[tikz]{standalone}
\usetikzlibrary{
  arrows.meta,
  shapes,
  positioning,
  calc,
  decorations.markings}

\tikzset{
  block/.style={
     rectangle,
     draw,
     fill=blue!10,
     rounded corners,
     text centered,
     text width = 7em,
     minimum height = 2em},
  line/.style={draw, -Latex}
  }

\begin{document}

\begin{tikzpicture}[every node/.style={block}]
% Place nodes
\node (optimization) {Given \\optimization problem};
\node [right of=optimization, node distance=4cm]  (critical) {Find \\ critical points};
\node [right of = critical, node distance=4cm] (second) {Apply Second Derivatives Test to each critical point};
\node[below left=1cm and 1cm of second](case one) {$D(a, b) = 0$};
\node[below = 1cm of second](case two) {$D(a, b) >0$};
\node[below right = 1cm and 1cm of second](case three) {$D(a, b) < 0$};
\node[below = 1cm of case one](no info){No information about critical point $(a, b)$};
\node[below = 1cm of case two](saddle){$(a, b)$ is a saddle point};
\node[below = 1cm of case three](more){Check $f_{xx}(a, b)$};
\node[on grid,below left = 1.5cm and 1.8cm of more](a){$f_{xx}(a, b) > 0$};
\node[on grid,below right = 1.5cm and 1.8cm of more](b){$f_{xx}(a, b) < 0$};
\node[below = 1cm of a](min){$(a, b)$ is a local min};
\node[below = 1cm of b](max){$(a, b)$ is a local max};
% Draw edges

\foreach \x/\y in {optimization/critical,
                   critical/second,
                   second/case one,
                   second/case two,
                   second/case three,
                   case one/no info,
                   case two/saddle,
                   case three/more,
                   more/a,
                   more/b,
                   a/min,
                   b/max}
   \draw [line] (\x) -- (\y);
\end{tikzpicture}
\end{document}
| improve this answer | |
  • This worked perfectly. The solution was so simple though - sorry to bother you with the question! – user56010 Aug 25 '14 at 21:39
  • @user56010 No bother at all, it may not be the most obvious thing to try. – Torbjørn T. Aug 25 '14 at 21:51

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.