5

I am not able to compile the following. I get an error no shape named a21 is known. What is the mistake I am making?

\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
aaammmm\tikzmark{a21} kkkkkkkkkk PPPPPPPPPPPPPPP\tikzmark{a22}
\begin{tikzpicture}[remember picture,overlay]
\draw[->] (a21) to[bend right] (a22);
\end{tikzpicture}
\end{document} 
3
  • 3
    Does (pic cs: a21) work? Aug 17 at 14:12
  • @Qrrbrbirlbel, I confirm that it does, at least on my TL2022.
    – Sigur
    Aug 17 at 14:42
  • @Qrrbrbirlbel is correct: since \tikzmark doesn't create a node (the very first version did, but now \tikzmarknode is used for that) then you need to use a different way to refer to its coordinates and that's what the (pic cs: ...) syntax is for. Aug 17 at 14:55

1 Answer 1

8

The correct syntax for referring to a tikzmark is (pic cs: <tikzmark name>). The syntax (<name>) refers to a node. Early in the development of tikzmark, I separated the remembering part from the node part of the original \tikzmark command so that the location that a tikzmark refers to can be used earlier in the document than the mark itself. Nodes, on the other hand, have to be used after they are defined (although an even later version of tikzmark introduced the save node key to enable entire nodes to be referred to before they are defined).

So the correct version of your code is, as Qrrbrbirlbel says in the comments:

\documentclass{article}
\usepackage{array}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}
aaammmm\tikzmark{a21} kkkkkkkkkk PPPPPPPPPPPPPPP\tikzmark{a22}
\begin{tikzpicture}[remember picture,overlay]
\draw[->] (pic cs: a21) to[bend right] (pic cs: a22);
\end{tikzpicture}
\end{document} 

For more on the development of tikzmark, see the package documentation. That also links back to many important questions on this site (important in the sense of guiding the development of tikzmark). It's also worth noting that since tikzmark changed in behaviour a few times since its inception, the syntax of using it also changed from time to time so it is worth checking the documentation particularly when looking at old questions/answers on this site that might have been based on an older version of the package.

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.