1

In the following code, I would like to connect the plus sign to the focusing rectangle containing 2 * 3 + 11 = 17. I have a connection but it is not the wanted one.

I do not want the small red line crossed off in green, and I would like a line starting from the PLUS sign.

What am I missing ?

enter image description here

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows, matrix}

\tikzset{ope/.style={circle,draw,fill=white,inner sep=1pt, outer sep=1pt},
block/.style={
  rectangle,
  draw=blue,
  thick,
  fill=blue!20,
  text width=5em,
  align=center,
  rounded corners,
  minimum height=2em},
blur/.style={opacity=0.3},
focus/.style={rectangle,
  thick,
  rounded corners,
  minimum height=2em,
  align=center,
  draw=red,
  text=magenta}}    

\begin{document}

% Source for decorated paths
%    * https://tex.stackexchange.com/a/507419/6880

\begin{tikzpicture}
  \matrix[matrix of nodes,
    row sep  = 1em,
    column sep = 1.5em
  ](mat){
                &  9665              &              && |[focus]| {$2 \times 3 + 11 = 17$}  \\
    |[block]| 2 &  |[blur]|488888887 & |[block]| 3                                         \\
                &  777               & |[block]| 11                                        \\
                &                    &  99                                                 \\
    };

  \draw[red] (mat-2-1) -- (mat-2-3) node[midway,draw,ope]{$\times$};

  \draw[red] (mat-2-3.east) -- ++ (1,0) -| ++ (0,-.5) coordinate[pos=0.5] (aux) |- (mat-3-3.east);

  \draw[red] (mat-3-3.east) -| (aux) node[pos=0.75,draw,ope]{$+$}  -| (mat-1-5.south);

  \draw[red,-triangle 60] (mat-1-5.west) -- ++ (-1,0); 
\end{tikzpicture}

\end{document}
1

How about using positioning to position the new node (instead of putting it into the matrix)?

\documentclass[12pt]{article}

\usepackage{tikz}
\usetikzlibrary{arrows, matrix,positioning}

\tikzset{ope/.style={circle,draw,fill=white,inner sep=1pt, outer sep=1pt},
block/.style={
  rectangle,
  draw=blue,
  thick,
  fill=blue!20,
  text width=5em,
  align=center,
  rounded corners,
  minimum height=2em},
blur/.style={opacity=0.3},
focus/.style={rectangle,
  thick,
  rounded corners,
  minimum height=2em,
  align=center,
  draw=red,
  text=magenta}}


\begin{document}

% Source for decorated paths
%    * https://tex.stackexchange.com/a/507419/6880

\begin{tikzpicture}
  \matrix[matrix of nodes,
    row sep  = 1em,
    column sep = 1.5em
  ](mat){
                &  9665              &              \\
    |[block]| 2 &  |[blur]|488888887 & |[block]| 3                                         \\
                &  777               & |[block]| 11                                        \\
                &                    &  99                                                 \\
    };

  \draw[red] (mat-2-1) -- (mat-2-3) node[midway,draw,ope]{$\times$};

  \draw[red] (mat-2-3.east) -- ++ (1,0) |- (mat-3-3.east)
   node[pos=0.25,draw,ope](plus){$+$}
   node[above right=1cm and 1cm of plus,focus] (f){$2 \times 3 + 11 = 17$} ;    
  \draw[red,-triangle 60] (plus) -| (f) (f.west) --  ++(-1,0); 
\end{tikzpicture}

\end{document}

enter image description here

|improve this answer|||||
  • Thanks but I would like the + to stay between and connect to 3 and 11. Then I would like a path from + to 2*3+11=37. (I'm very new to TikZ) – projetmbc Sep 8 '19 at 22:02
  • @projetmbc Yes, sorry, there was a typo |- (mat-2-3.east) needed to become |- (mat-3-3.east). – Schrödinger's cat Sep 8 '19 at 22:05
  • Thanks. I really need to practice TiKz. So cute and no so hard to read. – projetmbc Sep 8 '19 at 22:14
  • @projetmbc You're welcome! TikZ has become a really large package so it takes time to get used to it but I think on the long run it pays off. – Schrödinger's cat Sep 8 '19 at 22:17

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.