TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to draw a diagram like this:

enter image description here

My tikz code is as follows:

\documentclass{article}
\usepackage{tikz}
\usepackage[margin=15mm]{geometry}
\usepackage{calc}
\usetikzlibrary{matrix,arrows}
\usetikzlibrary{positioning,arrows}
\usetikzlibrary{shapes,arrows,fit,calc,positioning,automata}

\begin{document}
\tikzstyle{int}=[draw, minimum width=3 cm, minimum height=1 cm]
\tikzstyle{init} = [pin edge={to-,thin,black}]


\begin{tikzpicture}[node distance=5cm,auto,>=latex', scale = 1, transform shape]
    \tikzstyle{line} = [draw, -latex']
    \node [int] (a) { Box1 };
    \node [int] (b) [below of=a, node distance=4 cm] {Box2};

\end{tikzpicture}

\end{document}

which outputs as follows:

enter image description here

I don't understand how to draw such arrows at correct locations in tikz. I know only how to draw at center. How can I do this?

share|improve this question
up vote 4 down vote accepted

In this case, the let syntax could be used, as the following example illustrates:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,positioning}

\begin{document}

\begin{tikzpicture}
\node  (a) {A};
\node[above right=of a] (b) {B};
\draw[red,->] let \p1=(a), \p2=(b) in (a) -- (\x1,0.5*\x2) -| (b);
\end{tikzpicture}

\end{document}

enter image description here

Another possibility is to use the implicit syntax for the node coordinate system, using the name of a node together with an anchor or an angle separated by a dot as in (a.north) or (a.30); the following example uses this approach:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,calc,positioning}

\tikzset{int/.style={draw, minimum width=3 cm, minimum height=1 cm},
init/.style={pin edge={to-,thin,black}}}

\begin{document}

\begin{tikzpicture}[node distance=1cm,auto,>=latex']
\node [int] (a) { Box1 };
\node [int] (b) [below of=a, node distance=4 cm] {Box2};
\node[above =of a.150,align=center] (aux1) {Input 1 \\ From 1};
\node[above =of a.30,align=center] (aux2) {Input 2 \\ From 2};

\draw[->] (aux1) -- ($(aux1)!.6!(a.150)$) -| (a.110);
\draw[->] (aux2) -- ($(aux2)!.6!(a.30)$) -| (a.70);
\draw[->]  (a.south) -- +(0,-0.5) -| node[fill=white,near end,align=center,xshift=-0.75cm] (aux3) {Output 1 \\ From 1} (b.150);

\node[right =of aux3,align=center,xshift=-0.75cm] (aux4) {Input 3 \\ From 3};

\draw[->] (aux4.south) -- (aux4.south|-b.north);
\draw[->] (b.230) -- +(0,-1cm) node[anchor=north] {Yes};
\draw[->] (b.310) -- +(0,-1cm) node[anchor=north] {No};
\end{tikzpicture}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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