I am wondering whether there would be a simpler way to get a similar figure: (1) avoid adjusting by hand the size of each coloured box, (2) avoid computing by hand the middle of each box from which the arrows are drawn.




\node (ctr) {$\constraint{increasing\_max\_peak}$};
\fill[brown!20]  ($(ctr.south west)+(0.1,0)$)  rectangle ($(ctr.north west)+(2.07,0)$);
\fill[pink!20]   ($(ctr.south west)+(2.07,0)$) rectangle ($(ctr.north west)+(2.9,0)$);
\fill[violet!20] ($(ctr.south west)+(2.9,0)$)  rectangle ($(ctr.north east)-(0.1,0)$);
\node (ctr1) {$\constraint{increasing\_max\_peak}$};
\draw[->] ($(ctr.south west)+(1.085,0)$) -- ($(ctr.south west)+(1.085,-0.7)$) node[below] {\scriptsize \constraint{Condition}};
\draw[->] ($(ctr.south west)+(2.485,0)$) -- ($(ctr.south west)+(2.485,-0.3)$) node[below] {\scriptsize \constraint{Feature}};
\draw[->] ($(ctr.south west)+(3.35,0)$) -- ($(ctr.south west)+(3.35,-0.7)$) node[below] {\scriptsize \constraint{Pattern}};


enter image description here


You could for example use \subnodes from the tikzmark library. Note this requires the addition of the remember picture option to the tikzpicture environment. That lets you use the anchors of the subnodes to draw the boxes and arrows.

You could also make use of the backgrounds library to avoid having to draw the same node twice.

enter image description here




\begin{tikzpicture}[remember picture]
\node (ctr) {$\constraint{\subnode{i}{increasing}\subnode{a}{\_}\subnode{m}{max}\subnode{b}{\_}\subnode{p}{peak}}$};
\begin{scope}[on background layer]
  \fill[brown!20] (i.north west) rectangle (a.south);
  \fill[pink!20] (a.south) rectangle (m.north east);
  \fill[violet!20] (b.north |- p.north) rectangle (p.south  east);

  every node/.append style={font=\scriptsize}
  \draw [->] (i.south) -- ++(0,-0.7) node[below] {\constraint{condition}};
  \draw [->] (m.south) -- ++(0,-0.4) node[below] {\constraint{feature}};
  \draw [->] (p.south) -- ++(0,-0.7) node[below] {\constraint{pattern}};


  • Importing the package amsmath (which I also need in my document) breaks the proposed solution: for some unknown reason the coloured boxes do not cover any more completely the three subwords. – Nicolas Beldiceanu Sep 2 '18 at 6:02
  • @NicolasBeldiceanu Not sure exactly what happens, but remove the two $ from the ctr node. – Torbjørn T. Sep 2 '18 at 6:11
  • Yes removing the $ solves the problem. – Nicolas Beldiceanu Sep 2 '18 at 6:28

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.