I want to draw a figure like this
There are two problems: (1) the red and blue rectangle are not same height, (2) the label stack
and buffer
are not aligned center. I'm new to tikz, can anyone show some directions that I can improve the figure?
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',node distance=1cm]
\draw [help lines] (0,0) grid (6,2);
\node [text] (1) {I};
\node [text] (2) [right of=1] {booked};
\node [text] (3) [right of=2] {a};
\node [text] (4) [right of=3] {ticket};
\node [text] (5) [right of=4] {to};
\node [text] (6) [right of=5] {China};
\path (2) edge[bend right=70] node [above]{nsubj} (1);
\path (2) edge[bend left=90] node [above]{dobj} (4);
\path (4) edge[bend right=70] node [left]{det} (3);
\path (4) edge[bend left=70] node [above]{prep} (5);
\path (5) edge[bend left=70] node [above]{pobj} (6);
\draw [red,thick,minimum height=2cm] (stack) ($(1.north west)$) rectangle ($(2.south east)$);
\node [text,align=center] [below=stack] {stack};
\draw [blue,thick,minimum height=2cm] (buffer) ($(3.north west)$) rectangle ($(6.south east)$);
\node [text,align=center] [below=buffer] {buffer};
\end{tikzpicture}
\end{document}
Best Answer
Do you like to obtain something like this?
I significantly change your MWE:
chains
,fit
andquotes
,calc
, since it is not usedtxt
nodestxt
(text
is used name in TikZ and had not to be used for locally defined styles) and redefineedge
stylesquotes
Complete MWE: