3

I have to ask for your help again. I am trying to produce a block diagram, a really simple one. enter image description here

So far I have gotten to this part:

\documentclass{article}

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

%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>
\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{answer} = [rectangle, draw, text width=15em, text badly centered, node distance=1cm, inner sep=0pt, minimum height=4em]
\tikzstyle{block} = [rectangle, draw, text width=30em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [block] (development) {text};
\node [block, below of=development] (quantitive) {text};
\node [block, below of=quantitive] (significances) {text};
\node [block, below of=significances] (utility) {text};
\node [block, below of=utility] (optimization) {text};
\node [block, below of=optimization] (decide) {text?};\\
\matrix [column sep=2mm,row sep=3mm] {\node [answer, below of=decide, node distance=1cm] (answerno) {text}; & \node [answer, below of=decide, node distance=1cm] (answeryes) {text};\\};
% Draw edges
\path [line] (development) -- (quantitive);
\path [line] (quantitive) -- (significances);
\path [line] (significances) -- (utility);
\path [line] (utility) -- (optimization);
\path [line] (optimization) -- (decide);
\path [line] (decide) -- node {No} (answerno);
\path [line] (decide) -- node {Yes} (answeryes);
\path [line] (answerno) -- (development);
\end{tikzpicture}

\end{document}

And it produces a nasty view. Is there even an option to have two arrows like that? Or will I have to rethink the diagram design. Appreciate any suggestions. sleeping

3

An alternative, more concise code using macros from packages chain and quotes:

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta, chains, positioning, quotes}

\begin{document}
    \begin{tikzpicture}[
node distance = 5mm and 0mm,
  start chain = A going below,
  base/.style = {rectangle, draw, rounded corners,
                 minimum height=2em, text width=15em, align=flush center,
                 inner sep=2mm},
answer/.style = {base, text width=15em},
 block/.style = {base, text width=32em, on chain, join=by line},
  line/.style = {-Stealth},
                        ]
% Place nodes
    \begin{scope}[every node/.style={block}]
\node   {text};         % name: A-1
\node   {text};
\node   {text};
\node   {text};
\node   {text};
\node   {text};         %       A-6
    \end{scope}
\node   (answerno)  [answer, below right=of A-6.south west] {text};
\node   (answeryes) [answer, below  left=of A-6.south east] {text};
% Draw edges
\draw[line] (A-6.south -| answerno.north)     to ["No"] (answerno);
\draw[line] (A-6.south -| answeryes.north)   to ["Yes"] (answeryes);
\draw[line] (answerno.west) -- ++ (-2,0) |- (A-1);
\end{tikzpicture}
\end{document}

enter image description here

0
3

Some quick improvements:

  • \tikzstyle is obsolete, use \tikzset instead. See my code to see how to use it.
  • Although arrows is still supported, it's deprecated. You can use it if you prefer, but arrows.meta is the current library.
  • The library positioning should be used, changing from below of=..., to below =of....
  • The standalone class is very useful for showing small examples.
  • \path[draw] is equivalent to \draw, the second means less typing and neater code, though.

Output

enter image description here

Code

\documentclass[margin=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{positioning, shapes, arrows.meta}

\tikzset{
    answer/.style={rectangle, draw, text width=15em, text badly centered, node distance=1cm, inner sep=0pt, minimum height=4em},
    block/.style={rectangle, draw, text width=30em, text centered, rounded corners, minimum height=4em},
    line/.style={-{Stealth}}
}

\begin{document}
\begin{tikzpicture}[node distance = 5mm, auto]
% Place nodes
\node [block] (development) {text};
\node [block, below =of development] (quantitive) {text};
\node [block, below =of quantitive] (significances) {text};
\node [block, below =of significances] (utility) {text};
\node [block, below =of utility] (optimization) {text};
\node [block, below =of optimization] (decide) {text?};

\node [answer, below =of decide.south west, anchor=north west] (answerno) {text}; 
\node [answer, below =of decide.south east, anchor=north east] (answeryes) {text};
% Draw edges
\draw[line] (development) -- (quantitive);
\draw[line] (quantitive) -- (significances);
\draw[line] (significances) -- (utility);
\draw[line] (utility) -- (optimization);
\draw[line] (optimization) -- (decide);
\draw[{Stealth}-] (answerno) -- (answerno|-decide.south) node[right, midway] {No};
\draw[{Stealth}-] (answeryes) -- (answeryes|-decide.south) node[right, midway] {Yes};
\draw[line] (answerno.west) -- ++ (-2,0) |- (development.west);
\end{tikzpicture}
\end{document}
0

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.