7

The following code fails with the error ! Package pgf Error: No shape named `B' is known. There is no error for mark connection node=A. Seemingly the only accessible node is the one defined first. Is this expected?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[decoration={
    markings,
    mark=at position .33 with {\node [draw] (A) {A};},
    mark=at position .66 with {\node [draw] (B) {B};},
    mark connection node=B,
  }
  ]
  \draw [help lines] grid (3,2);
  \draw decorate { (0,0) -- (3,2) };
\end{tikzpicture}
\end{document}

1
  • And if I add a "phantom node" \node (B) {}; in the body of the tikzpicture, i.e. right before the grid, then code works AND the mark node breaks the path (the behavior I wanted originally). Strange.
    – tsj
    Jun 13 at 18:38
8

Surprisingly, naming the two nodes with the same name, works.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[decoration={
    markings,
    mark connection node=A,
    mark=at position .33 with {\node [draw] (A) {A};},
    mark=at position .66 with {\node [draw] (A) {B};}, % <<< name it with "A"
  }
  ]
  \draw [help lines] grid (3,2);
  \draw decorate { (0,0) -- (3,2) };
\end{tikzpicture}
\end{document}

enter image description here

Update: I've reported this to pgf-tikz, see https://github.com/pgf-tikz/pgf/issues/1024.

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.