9

I am having some issues with the following code:

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes}
\begin{document}

\begin{tikzpicture}[node distance=5mm, >=latex',
 block/.style = {draw, rectangle, minimum height=10mm, minimum width=28mm,align=center},
tblock/.style = {draw, trapezium, minimum height=10mm, 
                 trapezium left angle=75, trapezium right angle=105, align=center},
                        ]
 \node [block]                      (first)     {Bank of England\\ asset purchases};
 \node [block, right=of first]      (portfolio)   {Portfolio\\ rebalancing};
 \node [block, above=of portfolio] (policy) {Policy signalling};
 \node [block, above=of policy] (confidence) {Confidence};
 \node [block, below=of portfolio] (market) {Market liquidity};
 \node [block, below=of market] (money) {Money};
 \node [block, right=1cm of portfolio] (asset) {Asset prices\\ and the\\ exchange rate};
\node [block, right=1cm of money] (bank) {Bank lending};
\node [block, right=5cm of policy] (total) {Total wealth};
\node [block, right=5cm of market] (cost) {Cost of\\ borrowing};
\node [block, right=5cm of asset] (spending) {Spending and\\ income};
\node [block, right=1cm of spending] (inflation) {Inflation at 2\%};

\draw[->] (first) edge (portfolio);
\draw[->] (first.north) |- (policy.west);
\draw[->] (first.north) |- (confidence.west);   
\draw[->] (first.south) |- (market.west);
\draw[->] (first.south) |- (money.west);
\draw[->] (portfolio) edge (asset);
\draw[->] (policy.east) edge (asset.north);        
\draw[->] (market.east) edge (asset.south); 
\draw[->] (money) edge (bank);
\draw[<->] (bank.north) edge (asset.south);
\draw[->] (confidence.east) -| (asset.north);
\draw[->] (confidence.east) -| (spending.north);
\draw[->] (confidence.east) -| (inflation.north);
\draw[->] (asset.east) -| (total.south);
\draw[->] (asset.east) -| (cost.north);
\draw[->] (spending) edge (inflation);
\draw[->] (bank.east) -| (spending.south);
\draw[->] (total.east) -| (spending.north);
\draw[->] (cost.east) -| (spending.south);
\end{tikzpicture}

\end{document}

because I want to replicate the following diagram enter image description here

and I am unable to place double arrows connected in a single block. I have also problems with the end of some connectors as you can check if you run the code.

Thanks in advance for your time!!!

  • 1
    If you are replicating it, a design tip: It bothers me enormously how those 4 arrows end non-uniformly in "assets prices [...]". Try to make them en in a more elegant way! – Ander Biguri Apr 25 '16 at 14:40
  • Yes, you are also right but up to know I didn't know how ;) – José Apr 26 '16 at 7:51
8

You can define your arrow entry point by a certain angle around your node. So instead of saying spending.south you can say spending.270 which will result in the same. Knowing this, you can define whatever entry angle you desire.

I hope, this is what you meant:

% arara: pdflatex

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{arrows,positioning}
\usepackage{siunitx}

\begin{document}    
\begin{tikzpicture}[%
    ,node distance=5mm
    ,>=latex'
    ,block/.style = {%
        ,draw
        ,minimum height=10mm,minimum width=28mm
        ,align=center
        }
    ,every path/.style={->} 
    ]
    \node [block]                      (first)     {Bank of England\\ asset purchases};
    \node [block, right=of first]      (portfolio)   {Portfolio\\ rebalancing};
    \node [block, above=of portfolio] (policy) {Policy signalling};
    \node [block, above=of policy] (confidence) {Confidence};
    \node [block, below=of portfolio] (market) {Market liquidity};
    \node [block, below=of market] (money) {Money};
    \node [block, right=1cm of portfolio] (asset) {Asset prices\\ and the\\ exchange rate};
    \node [block, right=1cm of money] (bank) {Bank lending};
    \node [block, right=5cm of policy] (total) {Total wealth};
    \node [block, right=5cm of market] (cost) {Cost of\\ borrowing};
    \node [block, right=5cm of asset] (spending) {Spending and\\ income};
    \node [block, right=1cm of spending] (inflation) {Inflation at \SI{2}{\percent}};

    \draw (first) to (portfolio);
    \draw (first) |- (policy);
    \draw (first) |- (confidence);   
    \draw (first) |- (market);
    \draw (first) |- (money);
    \draw (portfolio) to (asset);
    \draw (policy.east) to (asset.140);        
    \draw (market.east) to (asset.220); 
    \draw (money) to (bank);
    \draw (money.10) to (asset.260);
    \draw[<->] (bank) to (asset);
    \draw (confidence) -| (asset);
    \draw (confidence) -| (spending.70);
    \draw (confidence) -| (inflation);
    \draw (asset) -| (total);
    \draw (asset) -| (cost);
    \draw (spending) to (inflation);
    \draw (bank) -| (spending.290);
    \draw (total) -| (spending.110);
    \draw (cost) -| (spending.250);
\end{tikzpicture}   
\end{document}

The edge syntax is for chains of arrows. You could save some lines of code (e.g. \draw (first) to (portfolio) edge (asset); if you connect several nodes in one chain at once. But I did not want to change your code too much and just replaced edge by to.

enter image description here

  • Thanks a lot! It worked perfectly!I'd also like to have dashed lines but I will try to figure out. – José Apr 26 '16 at 7:45
  • 1
    @José De nada. block/.style = {draw,minimum height=10mm,minimum width=28mm,align=center,solid},every path/.style={->,dashed} – LaRiFaRi Apr 26 '16 at 8:06
  • 1
    A sus pies LaRiFaRi, which means I kneel to you ;) – José May 3 '16 at 16:34
4

It does not really add much to the complete @LaRiFaRi answer but I wanted to show a different approach to define the ending point of a line using a convenient syntax provided by the library calc. Let's say you want to end the arrow between policy and asset at 1/4 of the distance between (asset.north west) and (asset.south west) (i.e. the left hand side of the rectangle wrapping the (asset) node). With the calc library you can easily do so:

\draw[->] (policy.east)--($(asset.north west)!.25!(asset.south west)$);

The syntax may appear tricky but in fact it's quite intuitive. You are after the node such that it is between (asset.north west) and (asset.south west) at 1/4=.25 of that distance; we wrap the calculation between dollar signs and the resulting point is in turn wrapped between parentheses. In other words the syntax would be: ($(first_node)!number_between_0_and_1!(second_node)$)

In a similar fashion you can also move from a point to a specified distance:

\draw[->] (policy.east)--($(asset.north west)+(0,-5mm)$);

that is, starting from (asset.north west) move downwards of a quantity equivalent to 5mm.

Of course you can do that using the notation (asset.<angle>) but it would involve some trigonometry and the result below could be hard to achieve (since there were only straight lines I've just used the -- notation between nodes to tackle the problem of the arrows):

coordinate using calc library

\documentclass[tikz,border=5mm]{standalone}
    \usetikzlibrary{arrows,positioning,shapes,calc}
\usepackege{siunitx}
\begin{document}
\begin{tikzpicture}[node distance=5mm, >=latex',
 block/.style = {draw, rectangle, minimum height=10mm, minimum width=28mm,align=center},
tblock/.style = {draw, trapezium, minimum height=10mm, 
             trapezium left angle=75, trapezium right angle=105, align=center},
                        ]
 \node [block]                      (first)     {Bank of England\\ asset purchases};
 \node [block, right=of first]      (portfolio)   {Portfolio\\ rebalancing};
 \node [block, above=of portfolio] (policy) {Policy signalling};
 \node [block, above=of policy] (confidence) {Confidence};
 \node [block, below=of portfolio] (market) {Market liquidity};
 \node [block, below=of market] (money) {Money};
 \node [block, right=1cm of portfolio] (asset) {Asset prices\\ and the\\ exchange rate};
\node [block, right=1cm of money] (bank) {Bank lending};
\node [block, right=5cm of policy] (total) {Total wealth};
\node [block, right=5cm of market] (cost) {Cost of\\ borrowing};
\node [block, right=5cm of asset] (spending) {Spending and\\ income};
\node [block, right=1cm of spending] (inflation) {Inflation at \SI{2}{\percent}};

\draw[->] (first) edge (portfolio);
\draw[->] (first.north) |- (policy.west);
\draw[->] (first.north) |- (confidence.west);   
\draw[->] (first.south) |- (market.west);
\draw[->] (first.south) |- (money.west);
\draw[->] (portfolio) edge (asset);
\draw[->] (policy.east)--($(asset.west)!.5!(asset.north west)$);        
\draw[->] (market.east)--($(asset.south west)!.5!(asset.west)$); 
\draw[->] (money) edge (bank);
\draw[->] ($(money.east)+(0,2.5mm)$)--(asset.south west);
\draw[->] ($(confidence.east)+(0,-2.5mm)$)--(asset.north west);
\draw[<->] (bank.north) -- (asset.south);
\draw[->] (confidence.east) -| (asset.north);
\draw[->] (confidence.east) -| (spending.north);
\draw[->] (confidence.east) -| (inflation.north);
\draw[->] (asset.east) -| (total.south);
\draw[->] (asset.east) -| (cost.north);
\draw[->] (spending) edge (inflation);
\draw[->] (bank.east) -| (spending.south);
\draw[->] (total.east) -| (spending.north);
\draw[->] (cost.east) -| (spending.south);
\end{tikzpicture}
\end{document}
  • Ok, thanks for the suggestion and what about the placing of the blocks? I mean, not only north, west south and east but more precise location. – José Apr 26 '16 at 7:50
  • What about them? The options right=1cm of ... isn't precise enough? You can say \node[block,anchor=south west] (newnode) at ($(oldnode.north east)+(1cm,1cm)$) {whatever}; that is anchor my (newnode) from the bottom left corner starting from (oldnode.north east) (already defined) and move 1cm on the right and 1cm upwards. Is that what you meant? – mirkom Apr 26 '16 at 8:54
  • Yes, precisely. Great! #FanOfLatexUsers ;) – José May 3 '16 at 16:33

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.