2

I have a problem with placing a node on a path drawn between two nodes in a TikZ matrix. I want to show the correspondence between the edge of a directed graph and entries of its adjacency matrix. My plan was to draw a dotted arrow between an edge of a digraph and the associated entry of its adjacency matrix.

I have two problems, one big, one small. The biggest one is that in the MWE below I cannot correctly place a node on the curved edge between E and C.

    \draw[blue,thick] (E) to [bend right] (C);
    \node (ece) [pos=0.2] {} (E) -- (C); % (ece) is nowhere the edge :-(

A smaller problem for me is that I don't get why the node (mdag)-3-3 isn't drawn with a circle; it does get drawn in blue.

Here follows the full MWE.

Many thanks.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

  \begin{tikzpicture}[>=stealth,->,shorten >=2pt,looseness=.5,auto]
    \matrix (dag)  [matrix of nodes,%
    nodes={outer sep=0pt,circle,minimum size=4pt,draw},
    column sep={2cm,between origins},
    row sep={2cm,between origins},
    ampersand replacement=\&] {
      |(A)| A \& |(C)| C \\
      |(D)| D \& |(E)| E \\
    };

    \draw (D) to [bend left] (A);
    \draw (E) to [bend right] (A);
    \draw[blue,thick] (E) to [bend right] (C);
    \node (ece) [pos=0.2] {} (E) -- (C); % (ece) is nowhere the edge :-(

  \matrix (mdag) at ([xshift=3cm]C.north east)
  [matrix of math nodes,
  anchor=TL.north west,
  every node/.style={font={\large\ttfamily}},
  row 3 column 3/.style={circle,blue}] {
    |(TL)|   &  A  &  C  \\
    D  &  1  &  0  \\
    E  &  1  & |(mce)| 1  \\
  };

  \draw[blue,fill] (ece) circle (1.5pt);
  \draw[dotted] (ece) to [bend right] (mce.center);
  \end{tikzpicture}

\end{document}
3
\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{matrix}

\begin{document}

  \begin{tikzpicture}[>=stealth,->,shorten >=2pt,looseness=.5,auto,
    C/.style = {%circle
                circle, fill=blue, inner sep=1pt}
                        ]
    \matrix (dag)  [matrix of nodes,%
    nodes={outer sep=0pt,circle,minimum size=4pt,draw},
    column sep={2cm,between origins},
    row sep={2cm,between origins},
    ampersand replacement=\&] {
      |(A)| A \& |(C)| C \\
      |(D)| D \& |(E)| E \\
    };

    \draw (D) to [bend left] (A);
    \draw (E) to [bend right] (A);
    \draw[blue,thick] (E) to [bend right] node[C,right=1mm] (ece) {}  (C); % <--- see changes

  \matrix (mdag) at ([xshift=3cm]C.north east)
  [matrix of math nodes,
  anchor=TL.north west,
  every node/.style={font={\large\ttfamily}},
  row 3 column 3/.style={circle,blue}] {
    |(TL)|   &  A  &  C  \\
    D  &  1  &  0  \\
    E  &  1  & |(mce)| 1  \\
  };

  \draw[dotted] (ece) to [bend right] (mce.center);
  \end{tikzpicture}

\end{document}

gives:

enter image description here

Is this what you're looking for?

My node lies on the edge, yours doesn't determine any coordinate to be at. Correct placement of node is \node at (<coordinate) {...}; but you wrote \node (ece) [pos=0.2] {} (E) -- (C) and tikz got lost... If you change it to \path (E) -- node (ece) [pos=0.2] {}(C), the node does appear at 20% distance from E to C.

  • Yes, that's great. Thanks a lot. But I don't get why yours worked. Or, more immediately, why mine didn't. Nonetheless, thanks again. – healyp Sep 1 '17 at 18:33
  • see added explanation. – Zarko Sep 1 '17 at 18:44
  • @healyp In my understanding, you're unhappily (might've worked but happens not to...) mixing the path syntax -- with the node placement one ;) Feel free to upvote if the answer helped (which obviously, it does, since you accepted !) – marsupilam Sep 1 '17 at 19:23

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.