Can I do arithmetic on tikzmark
points? For example if I have \tikzmark{A}
and \tikzmark{B}
can I find their midpoint?
-
Thanks Marmot! The \tikzmark part of your example works fine, but the \tikzmarknode is an "undefined control sequence" for me, even after reinstalling MacTex/Tex Live. I guess it's in some version of the tikz packege that has not yet been added to the main distribution?– tcpDec 26, 2018 at 6:58
1 Answer
Welcome to TeX.SE! You can use calc
for that. In general, the midpoint between a
and b
is given by ($(a)!0.5!(b)$)
. One slight subtlety is that you have to prepend pic cs:
to the \tikzmark
coordinates, but not for \tikzmarknode
nodes. The following MWE illustrates this.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{tikzmark,calc}
\begin{document}
Hello\tikzmark{A} something else\tikzmark{B}.\begin{tikzpicture}[overlay,remember picture]
\draw[red,latex-] ($(pic cs:A)!0.5!(pic cs:B)$) -- ++(0,-1);
\end{tikzpicture} \tikzmarknode{H}{Hello} world and \tikzmarknode{M}{marmots}!\begin{tikzpicture}[overlay,remember picture]
\draw[red,latex-] ($(H)!0.5!(M)$) -- ++(0,-1);
\end{tikzpicture}
\end{document}
-
1