8

My problem is very similar to this question. However, I'm unable to use this solution in my figure.

I want to connect two nodes with an arrow which has two corners. Here is my code:

\documentclass[12pt]{article}
\usepackage{setspace,amsmath,graphicx,float}
\usepackage[english]{babel}
\usepackage[natbibapa]{apacite}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,arrows.meta,positioning,calc}
\begin{document}
\begin{figure}[H] 
\centering
\tikzstyle{block} = [draw, rectangle, minimum height=5.5em, minimum width=19em]
\tikzstyle{smallblock} = [draw, rectangle, minimum height=5.5em, minimum width=9em]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]
\begin{tikzpicture}[auto,node distance=7cm,>=latex',align=center]
    \node [input, name=input] {};
    \node [block, rounded corners=5pt, right of=input] (A) {Start with the narrowest product\\ or geographic market definition.};
    \node [block, rounded corners=5pt, below of=A, node distance=3.5cm] (B) {Is it profitable for a monopoly producer of\\ that product to increase prices in a small but\\ significant and nontransitory way?};  
    \node [block, rounded corners=5pt, below of=B, node distance=3.5cm] (C) {There must be at least one good substitute\\ excluded from the current market definition.\\ Expand the market to include it.};   
    \node [block, rounded corners=5pt, below of=C, node distance=3.5cm] (D) {Now have a multiproduct monopolist.\\ Could he profitably raise prices?}; 
    \node [smallblock, rounded corners=5pt, right of=D, node distance=8cm] (E) {Stop.\\ Market definition\\ is wide enough.}; 
    \draw [-{Latex[length=3mm]}] (A) -- node[auto][name=1] [right]{} (B);    
    \draw [-{Latex[length=3mm]}] (B) -- node[auto][name=2] [right]{No} (C);       
    \draw [-{Latex[length=3mm]}] (C) -- node[auto][name=3] [right]{} (D);     
    \draw [-{Latex[length=3mm]}] (D) -- node[auto][name=4] [above]{Yes} (E);
    \draw [-{Latex[length=3mm]}] (B) -| node[near start][name=5] [above]{Yes} (E); 
    \draw [-{Latex[length=3mm]}] (D) -- +(0,1)|- node[auto][name=6] [left]{No} (C);                        
\end{tikzpicture} 
\caption[Illustration of an HMT decision tree]{Illustration of an HMT decision tree \citep{QuantTech}.}\label{AlgorithmHMT}
\end{figure}
\end{document}

I want to connect block D with C (see the last \draw), but the code -- +(0,1)|- node (as in the other question) does not work. I tried to alter it of course, but I'm not really making progress.

Can anyone please help?

Malganas
  • 503
  • 1
    See this question http://tex.stackexchange.com/questions/55068/is-there-a-tikz-equivalent-to-the-pstricks-ncbar-command – percusse Dec 28 '16 at 14:52

1 Answers1

12

Like this?

enter image description here

(I guess that you like to have something like the above picture)

I rewrote your MWE significantly

  • deprecated \tikzstyle{<name>} = [...] I replace with options of tikzpicture as <name>/.style = {....} (see MWE below)
  • with tikzlibrary{positioning} the correct syntax is for example left=of <node name>
  • for node distance I consider positioning again and define node distance = <vertical> and <horizontal>. for distance I select far smaller lengths than you (otherwise the picture is out of page)
  • for relative positioning with + you need explicit to define anchor of node: (D.west) -- + (-1,0).

Complete MWE:

\documentclass[12pt]{article}
\usepackage{setspace,amsmath,graphicx,float}
\usepackage[english]{babel}
\usepackage[natbibapa]{apacite}
\usepackage{times}
\usepackage{tikz}
\usetikzlibrary{arrows, arrows.meta, calc, positioning, quotes, shapes}

\begin{document}
\begin{figure}
\centering
    \begin{tikzpicture}[
    auto,
    node distance = 11mm and 22mm,
      base/.style = {draw, rounded corners=5pt, minimum height=5.5em,
                     align=center},
     block/.style = {base, minimum width=19em},
smallblock/.style = {base, minimum width=9em},
                        ]
\coordinate (in);
\node [block,right=of in] (A) {Start with the narrowest product\\ 
                               or geographic market definition.};
\node [block,below=of A ] (B) {Is it profitable for a monopoly producer of\\ 
                               that product to increase prices in a small but\\ 
                               significant and nontransitory way?};
\node [block,below=of B ] (C) {There must be at least one good substitute\\ 
                               excluded from the current market definition.\\ 
                               Expand the market to include it.};
\node [block,below=of C ] (D) {Now have a multiproduct monopolist.\\ 
                               Could he profitably raise prices?};
\node [smallblock,right=of D] (E) {Stop.\\ 
                                   Market definition\\ 
                                   is wide enough.};
\draw [-{Latex[length=3mm]}] 
    (A) edge                    (B) 
    (B) edge ["No"]             (C)  
    (C) edge                    (D) 
    (D) edge ["Yes"]            (E);
\draw [-{Latex[length=3mm]}] 
    (B) -| node[pos=0.25,name=5] {Yes} (E);
\draw [-{Latex[length=3mm]}] 
    (D.west) -- +(-1,0) |- node[pos=0.25] {No} (C);
    \end{tikzpicture}
\caption[Illustration of an HMT decision tree]
        {Illustration of an HMT decision tree \citep{QuantTech}.}
    \label{AlgorithmHMT}
\end{figure}
\end{document}
Zarko
  • 296,517
  • Thank you so much @Zarko! That's exactly what I wanted and I'm glad that I have a working sample of a pro. I picked my code up from various sources and I knew it was amateurishly done. Now I finally have something to analyse how it is done correctly. – Malganas Dec 28 '16 at 15:57