I'm trying to draw this diagram in tikzpicture
with beamer:
and I'm having troubles in drawing the arrows going horizontally into the right node (Couple instruction DataFrame). The best I could do is to specify the anchor using an angle:
\documentclass[draft]{beamer}
\usepackage{pgfplots}
\usetikzlibrary{shapes.geometric, arrows, positioning, fit, backgrounds}
\begin{document}
\tikzstyle{model} = [rectangle, rounded corners,
minimum width=4cm, minimum height=1cm,
text centered, align=center,
draw=black, fill=red!30]
\tikzstyle{artifact} = [rectangle,
minimum width=1cm, minimum height=1cm,
text centered, align=center,
draw=black, fill=blue!30]
\tikzstyle{prediction} = [minimum width = 3cm,
text centered, align = center]
\tikzstyle{function} = [minimum width = 3cm,
rectangle, rounded corners,
draw=red!70!white, fill=red!50!white,
text centered, align = center]
\tikzstyle{arrow} = [thick,->,>=stealth]
\begin{frame}{Instruction overhead}
\begin{center}
\begin{tikzpicture}[node distance=0.05cm and 1cm]
\onslide<2->{\node (sm) [model] {Single instruction\\predictor};}
\onslide<2->{\node (hm) [below=of sm, function] { \texttt{hamming} };}
\onslide<2->{\node (bw) [below=of hm, function] { \texttt{get\_binary\_weight} };}
\onslide<2->{\node (mn) [below=of bw, function] { \texttt{get\_mnemonic} };}
\onslide<1->{\node (instr1) [left = of sm, align=center] {First\\instruction};}
\onslide<1->{\node (instr2) [below = of instr1, align=center] {Second\\instruction};}
\onslide<2->{\draw [arrow, draw=gray] (instr1) -- ++ (1.5,0) |- (sm.175);}
\onslide<2->{\draw [arrow, draw=gray] (instr1) -- ++ (1.5,0) |- (hm.175);}
\onslide<2->{\draw [arrow, draw=gray] (instr1) -- ++ (1.5,0) |- (bw.175);}
\onslide<2->{\draw [arrow, draw=gray] (instr1) -- ++ (1.5,0) |- (mn.175);}
\onslide<2->{\draw [arrow, draw=lightgray] (instr2) -- ++ (1.4,0) |- (sm.185);}
\onslide<2->{\draw [arrow, draw=lightgray] (instr2) -- ++ (1.4,0) |- (hm.185);}
\onslide<2->{\draw [arrow, draw=lightgray] (instr2) -- ++ (1.4,0) |- (bw.185);}
\onslide<2->{\draw [arrow, draw=lightgray] (instr2) -- ++ (1.4,0) |- (mn.185);}
\onslide<3->{\node (df) [right = of sm, artifact] {Couple instruction\\DataFrame};}
\onslide<3->{\draw [arrow, draw=gray] (sm.5) -| ([shift={(-0.5,0.3)}] df.west) -- (df.169.5);} % <- HERE
\onslide<3->{\draw [arrow, draw=lightgray] (sm.355) -| ([shift={(-0.4,-0.3)}] df.west) -- (df.-169.5);}
\onslide<3->{\draw [arrow] (hm) -| ([shift={(-0.3,0)}] df.west) -- (df);}
\onslide<3->{\draw [arrow, draw=gray] (bw.5) -| ([shift={(-0.5,0.3)}] df.west) -- (df.169.5);}
\onslide<3->{\draw [arrow, draw=lightgray] (bw.355) -| ([shift={(-0.4,-0.3)}] df.west) -- (df.-169.5);}
\onslide<3->{\draw [arrow, draw=gray] (mn.5) -| ([shift={(-0.5,0.3)}] df.west) -- (df.169.5);}
\onslide<3->{\draw [arrow, draw=lightgray] (mn.355) -| ([shift={(-0.4,-0.3)}] df.west) -- (df.-169.5);}
\end{tikzpicture}
\end{center}
\end{frame}
\end{document}
but it's extremely fragile. I've tried to make a dummy hidden node, but for some reason the y shift seems to be not working:
\onslide<3->{\node (df) [right = of sm, artifact] {Couple instruction\\DataFrame};}
% \onslide<3->{\draw [arrow, draw=gray] (sm.5) -| ([shift={(-0.5,0.4)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow, draw=lightgray] (sm.355) -| ([shift={(-0.4,-0.4)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow] (hm) -| ([shift={(-0.5,0)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow, draw=gray] (bw.5) -| ([shift={(-0.5,0.4)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow, draw=lightgray] (bw.355) -| ([shift={(-0.4,-0.4)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow, draw=gray] (mn.5) -| ([shift={(-0.5,0.4)}] df.west) -- (df);}
% \onslide<3->{\draw [arrow, draw=lightgray] (mn.355) -| ([shift={(-0.4,-0.4)}] df.west) -- (df);}
\node (dfu) at ([yshift=-1] df.west) {};
\draw[arrow] (dfu.east|-df.west) -- (df.west);
Is there a more robust way to do this? And what's wrong with my attempt? Thanks!
model/.style={ }
statement?,
model,
function,
artifact. By the way, the
xshift` andyshift
keys work in the canvas coordinate system so their values will always be length meaning-1
is actually-1pt
. I'd use one of thegenerate anchor
keys so that you don't have to mess around withyshift
s (though we can also create nicer keys for that). Libraryext.paths.ortho
also helps.\coordinate (dfu) at ([xshift=-5mm] df.west); \draw[arrow] (hm) -| (dfu) -- (df);
A node always has a size and a shape and a border which always get in the way.